Hi all.
I have a for each loop which looks like this:
The purpose of the code is to copy a number in a cell in a row and insert it in the following row-cell. so for instance if cell A4 has a value, that same value should be inserted in to B4, C4 and so on. In the event of a change of month (lets say a change from month number 5 to 6), the month-number goes up by 1 and the copy/pasting should continue. The trigger for the month-change is that the day-value (m) becomes 1.
However, whenever the month changes, the loop stops and nothing more happens. Any help would be greatly appreciated.
I have a for each loop which looks like this:
VBA Code:
sub monthnumber()
Worksheets("ws1").Range("K4:AS4").Clear
Worksheets("ws1").Range("K8:AS8").Clear
Range("K4").Value = Month(Worksheets("ws1").Range("M2"))
m0 = Month(Worksheets("ws1").Range("M2"))
For Each m In rng
If m.Value <> 1 Then
m.Offset(-3, 1).Value = m.Offset(-3, 0).Value
ElseIf m.Value = 1 Then
m.Offset(-3, 0).Value = m.Value + m0
m0 = m0 + 1
End If
Next m
end sub
The purpose of the code is to copy a number in a cell in a row and insert it in the following row-cell. so for instance if cell A4 has a value, that same value should be inserted in to B4, C4 and so on. In the event of a change of month (lets say a change from month number 5 to 6), the month-number goes up by 1 and the copy/pasting should continue. The trigger for the month-change is that the day-value (m) becomes 1.
However, whenever the month changes, the loop stops and nothing more happens. Any help would be greatly appreciated.