Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Run script on cells in VBA Macro

In an Excel 2010 worksheet I want to build a Macro in VBA
I have a column with data from A2-A30000
I want to run a macro from top to bottom that is the current cell = "" set it to the cell above

I program in VB and am rusty in VBA syntax


So that starting at row 2

1002


1003

Would become
1002
1002
1002
1003
Avatar of nutsch
nutsch
Flag of United States of America image

Something like this?

Sub CopyDownEmpty()
'This macro takes the selected range and for each empty cell, _
copies the value of the cell above
Dim cl As range, rng As range

Set rng = [a2:a30000]

application.ScreenUpdating = False 'turns off screen updating

If application.WorksheetFunction.CountIf(rng, "") > 0 Then
    rng.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    rng.EntireColumn.Copy
    rng.EntireColumn.PasteSpecial xlPasteValues
Else
    MsgBox "No empty cells to fill"
End If

application.CutCopyMode = False

application.ScreenUpdating = True 'turns screen updating back on
End Sub

Open in new window


Thomas
Avatar of Larry Brister

ASKER

nutsch:
That works when there's a number in the cell
But when theres text like "Bill" it inserver =R[-1]C
ASKER CERTIFIED SOLUTION
Avatar of nutsch
nutsch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect, thanks
Follow-up question coming