Excel Macro

B

Bongard

Hi I am trying to make a macro where if column A is blank, the macro
then copys the info from the row above in columns A, B, E, F,G and K
down to the row where A is Blank. For example:

A B C D
E
xyz abc def ghi
jkl
asj lop


After macro was run would look like this:

A B C D
E
xyz abc def ghi
jkl
xyz abc asj lop
jkl

Any ideas? Thanks!

-Brian
 
S

Stefi

Sub fillblank()
Dim blankcells As Range
On Error GoTo noblank
Set blankcells = Columns("A").SpecialCells(xlBlanks)
For Each cella In blankcells
cella.Value = Range("A" & cella.Row - 1).Value
Range("B" & cella.Row).Value = Range("B" & cella.Row - 1).Value
Range("E" & cella.Row).Value = Range("E" & cella.Row - 1).Value
Range("F" & cella.Row).Value = Range("F" & cella.Row - 1).Value
Range("G" & cella.Row).Value = Range("G" & cella.Row - 1).Value
Range("K" & cella.Row).Value = Range("K" & cella.Row - 1).Value
Next cella
noblank:
End Sub

But what should happen if the first row is empty and there is no row above?

Regards,
Stefi


„Bongard†ezt írta:
 
B

Bongard

That is a good question. I am hoping that the macro works its way down
the page so that if there happen to be two blank rows (in column A) in
a row that after the macro is run the first one will fill and then when
it gets to the next row the row above it will already be filled so that
there is data in the cells to copy and paste. I hope this makes sense.
Also, the data starts from the first row in the sheet so there will
never be a case where there are blank rows on the top of the sheet
however when it gets to the bottom of the data set (approx 690 rows) I
would like it to end the macro so that it doesn't keep doing this all
the way down to row 65,536

Thanks in advance!

Brian
 

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