I am trying to run my code:
Sub Test()
Dim vuosi As Integer
Dim kk As Integer
Dim cF As Range
Dim c As String
Dim cell As Range
vuosi = Application.InputBox(Prompt:="Syötä vuosi, jota haluat tarkastella.")
kk = Application.InputBox(Prompt:="Syötä kuukausi(1-12), jota haluat tarkastella.")
If vuosi = 2014 Then
c = "BU"
ElseIf vuosi = 2015 Then
c = "CG"
ElseIf vuosi = 2016 Then
c = "CS"
End If
ActiveSheet.Range("F11:F60").Select
For Each cell In Selection
Cells(ActiveCell.Row, c).Activate
Set cF = Range(ActiveCell.Offset(0, kk - 12), ActiveCell.Offset(0, kk)).Find(What:=1, LookIn:=xlFormulas, LookAT:=xlPart, SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False)
If Not cF Is Nothing Then
Cells(ActiveCell.Row, "F").Interior.ColorIndex = 6
End If
Next cell
End Sub
It doesn't work properly. It seems the For Each loop goes through only the first line. Can anyone tell me why?
The program should go through all the cells in column F. For each row it checks if there is value 1 found in specific cells. If yes, the cell in F column should be painted yellow. Else the program continues till the last value found in column F. (in my Test I used just Range("F11:F60")