I need to insert or delete some rows depending on what a variable states.
Sheet1 has a list of data. With sheet2 which is formatted, i want to copy that data so sheet2 is just a template and sheet1 is like a user form.
What my code does up until the for loop is get the number of rows in sheet 1 which only contains data and also the number of rows in sheet2 which contains data.
If the user adds some more data to sheet1 then i need to insert some more rows at the end the data in sheet2 and if the user deletes some rows in sheet1 the rows are deleted from sheet2.
I can get the number of rows on each so now how many to insert or delete but that's where i've come unstuck. How would I insert/delete the correct amount of rows. Also i wanted to alternate the rows colours between white and grey.
I did think that it might be an idea to delete all the rows on sheet2 then insert the same amount of rows that are in sheet1 using the alternating row colours but then again i did see something about using mod in the conditional formatting.
Can anyone please help?
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim listRows As Integer, ganttRows As Integer, listRange As Range, ganttRange As Range
Dim i As Integer
Set listRange = Columns("B:B")
Set ganttRange = Worksheets("Sheet2").Columns("B:B")
listRows = Application.WorksheetFunction.CountA(listRange)
ganttRows = Application.WorksheetFunction.CountA(ganttRange)
Worksheets("Sheet2").Range("A1") = ganttRows - listRows
For i = 1 To ganttRows - listRows
'LastRowColA = Range("A65536").End(xlUp).Row
Next i
If Target.Row Mod 2 = 0 Then
Target.EntireRow.Interior.ColorIndex = 20
End If
End Sub
=MOD(ROW(),2)=0, then Format -> Fill with the appropriate color.