How to paste a value for a preceding row if a cell is empty

Joined
Nov 6, 2009
Messages
1
Reaction score
0
I am given CSV output as per attached



How do I write a function for a large version of this spreadsheet that

Copies Jo Mack into the empty rows below it? i,e, Pseudocode below

Examine all rows beginning at row 2 (2 to x)
if cell Ax null then-->copy and paste A(x-1)
 

Attachments

  • EmptyCellExample.pdf
    19.7 KB · Views: 127
Joined
Sep 20, 2009
Messages
47
Reaction score
2
I have added one more row for checking purposes
A6 blank
B6 to D6
Oranges 45 6.23

try this macro and confirm whether it does what you want

Code:
Sub test()
 Dim j As Integer, r As Range, r1 As Range
 On Error Resume Next
 j = Range("B2").End(xlDown).Row
 Set r = Range("a2")
 Do
 Set r1 = r.End(xlDown)
 
 If r1.Row > j Then Set r1 = Cells(j, "A")
 Range(r, r1).SpecialCells(xlCellTypeBlanks).Select
 Selection.Formula = r.Value
 
 Set r = r1
 If Cells(r1.Row + 1, "b") = "" Then Exit Do
 Loop
 End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top