Excel macro - VBA code query
I have an Excel Spreadsheet with rows of data in several categories.
Each category is separated by two blank rows. In column G, in the blank
cell immediately above each category, I write the category heading - a
process I have already automated using the macro Copy_Title.
To save having to manually run down column G and run Copy_Title in the
appropriate cells, I am now trying to write another macro which will
automate this task. However, my efforts have not achieved success so
far:
Sub Copy_Title_Auto()
Range("G2").Select
Dim LastRow As Long
Dim x As Long
Dim y As Long
y = ActiveCell.Column
LastRow = Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row
Application.ScreenUpdating = False
For x = LastRow To 2 Step -1
If Cells(x, y).Value = "" And Cells(x - 1, y).Value = "" Then
With Cells(x, y)
Call Copy_Title
End With
End If
Next x
Application.ScreenUpdating = True
End Sub
Can anyone help please?
Many thanks.
|