Hi,
I am trying to write a code that will copy the contents of a cell - a month
- into all subsequent empty cells, unless another month is encountered. I
then want this new month to be copied into subsequent empty cells, until
another month is encountered. And so on. This will occur in one column only.
Reason: I have a spreadsheet that varies in size and format apart from one
column. The column contains one reference only per month's worth of line
items that follow. The line items do not contain any reference to the month
that they relate to. I am trying to write a code that will copy the only
reference of the month into every row that contains a line item for that
month, and repeat this for however many months there may be.
This is what I have so far, but it does not work:
Sub Month_copy
Dim CURRPERIOD As String
Dim CELL As Range, RNG As Range
With ActiveSheet
Set RNG = .Range(.Range("A1:a10000"), .Range("A1:A10000").End(xlDown))
End With
For Each CELL In RNG
CURRPERIOD = ActiveCell.Value
If ActiveCell = "" Then
ActiveCell.Value = CURRPERIOD
Else
CURRPERIOD = ActiveCell.Value
End If
Next
End sub
What I am trying to say is if the cell is blank, paste in the current month
value and move onto the next. If it is not blank, it must be a month
reference, therefore copy this into the subsequent blank cells.
Thanks in advance for any help received. (Hope this makes sense)
Ewan.
Bookmarks