So i have this VBA code
Option Explicit
Sub ValuesByColors()
Const Blk = 0
Const DkGray = 65535
Const LtGray = 12632256
Const OW = 16777215
Dim r As Range
Application.ScreenUpdating = False
For Each r In Range("A1:Q11").Cells
Select Case r.Interior.Color
Case Is = Blk
r.Value = 0
Case Is = DkGray
r.Value = 3
Case Is = LtGray
r.Value = 10
Case Is = OW
r.Value = 21
End Select
Next r
Application.ScreenUpdating = True
End Sub
but i want the range of which
"For Each r In Range("A1:Q11").Cells"
to change to last row but the following does not work
Option Explicit
Sub ValuesByColors()
Dim lastrow As Long
lastrow = Range("A" & Rows.Count).End(xlUp).Row
Const Blk = 0
Const DkGray = 65535
Const LtGray = 12632256
Const OW = 16777215
Dim r As Range
Application.ScreenUpdating = False
For Each r In Range("D1").AutoFill Destination:=Range("D1:S" & lastrow)
Select Case r.Interior.Color
Case Is = Blk
r.Value = 0
Case Is = DkGray
r.Value = 3
Case Is = LtGray
r.Value = 10
Case Is = OW
r.Value = 21
End Select
Next r
Application.ScreenUpdating = True
End Sub
Bookmarks