VBA - Copying a line to the next non-blank line and repeat - help

Eean

New Member
Joined
May 26, 2010
Messages
44
I have several large documents that need data filling in and I'm trying to work out the best way to do it.
I need the contents of A and B columns copying down the rows to the last blank cell then the same again for the next non blank cells.

mrexcel.png


I'm hoping someone can help - also if there's something simple that I've missed, please let me know.
Thanks in advance
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Code:
Sub Fill_Blanks()
Dim LastRow As Long
Application.ScreenUpdating = False
LastRow = ActiveSheet.UsedRange.Rows.Count
With Range(Cells(1, 1), Cells(LastRow, 2))
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    .Copy
    .PasteSpecial xlValues
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
hello,

you can use this: you just need to select all of your data, and it will autofill for you

Code:
Sub Copia1()
Dim my_range, my_cells As Range
Set my_range = Selection
    For Each my_cells In my_range
        If IsEmpty(my_cells) = True Then
            my_cells = my_cells.Offset(-1, 0)
        End If
    Next my_cells
End Sub
 
Upvote 0
Code:
Sub Fill_Blanks()
Dim LastRow As Long
Application.ScreenUpdating = False
LastRow = ActiveSheet.UsedRange.Rows.Count
With Range(Cells(1, 1), Cells(LastRow, 2))
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    .Copy
    .PasteSpecial xlValues
End With
Application.ScreenUpdating = True
End Sub

This only seems to be copying the data from Column B?
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top