I have an excel file, where I need to copy-paste rows, starting from row 3. If cell in column C is grey (RGB: 191,191,191) to copy paste untill nexy grey row.
Below you can see what I achieved so far. But I do something wrong I think.. So when I check
- rownum = 12 ( which is correct , row 13 is where first grey cell is )
- lastrow = 172 ( also correct )
- startrow = here is problem I think, it is always 0 , I don't know why.
Any help if possible will be appreciated. thanks in advance..
Dim rownum As Long
Dim colnum As Long
Dim startrow As Long
Dim endrow As Long
Dim lastrow As Long
rownum = 3
colnum = 3
lastrow = ActiveSheet.Range("C65536").End(xlUp).Row
With ActiveSheet.Range("C3:C" & lastrow)
For rownum = 3 To lastrow
Do
If .Cells(rownum, 3).Interior.Color = RGB(191, 191, 191) Then
startrow = rownum
End If
rownum = rownum + 1
If (rownum > lastrow) Then Exit For
Loop Until .Cells(rownum, 3).Interior.Color = RGB(191, 191, 191)
endrow = rownum
rownum = rownum + 1
ActiveSheet.Range(Cells(startrow, 2), Cells(endrow, 17)).Copy
'Sheets("Result").Select
'Range("A1").Select
'Sheets("Result").PasteSpecial xlPasteValuesAndNumberFormats
Next rownum
End With
End Sub ```