Reputation: 57
I don't understand why this code has compile error Next without For Please help :(
Sub DefColorCodes()
For i = 2 To 5
Range("actReg").Value = Range("Sheet1!A" & i).Value
ActiveSheet.Shapes.Range("actReg").Select
With Selection.ShapeRange.Fill.ForeColor.RGB = Range(Range("actRegCode").Value).Interior.Color
Next i
Range("B17").Select
End Sub
Upvotes: 2
Views: 638
Reputation: 2016
You are using a With
statement inside your for loop with out a End With
Upvotes: 2
Reputation: 6075
You aren't ending your With
. Add an End With
line at some point before your Next i
line.
Sub DefColorCodes()
For i = 2 To 5
Range("actReg").Value = Range("Sheet1!A" & i).Value
ActiveSheet.Shapes.Range("actReg").Select
With Selection.ShapeRange.Fill.ForeColor.RGB = Range(Range("actRegCode").Value).Interior.Color
End With
Next i
Range("B17").Select
End Sub
In this case it's quite possible that you didn't mean to use a With
at all:
Sub DefColorCodes()
For i = 2 To 5
Range("actReg").Value = Range("Sheet1!A" & i).Value
ActiveSheet.Shapes.Range("actReg").Select
Selection.ShapeRange.Fill.ForeColor.RGB = Range(Range("actRegCode").Value).Interior.Color
Next i
Range("B17").Select
End Sub
Upvotes: 7