paste data in column B until finds blank cell in column A

kshitij_dch

Active Member
Joined
Apr 1, 2012
Messages
362
Office Version
  1. 365
  2. 2016
  3. 2007
Platform
  1. Windows
I am looking for a code that will copy last used cell (Xlup) in column B and paste in blank cells in column B untill finds blank cell in column A
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG10Nov59
[COLOR="Navy"]Dim[/COLOR] LstA [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] LstB [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
LstA = Range("A" & Rows.Count).End(xlUp).Row
LstB = Range("B" & Rows.Count).End(xlUp).Row
[COLOR="Navy"]If[/COLOR] LstB < LstA [COLOR="Navy"]Then[/COLOR]
    [COLOR="Navy"]With[/COLOR] Cells(LstB, "B")
        .Resize(LstA - LstB + 1).Value = .Value
    [COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Check this

Sub copy_cl_A_to_B()
Dim row_bla As Long, lrb As Long, i As Long
For Each cell In Columns(1).Cells
If IsEmpty(cell) = True Then row_bla = cell.Row: Exit For
Next cell
If row_bla = 1 And Cells(1, 1).Value2 = "" Then
MsgBox "Nothing to copy"
Exit Sub
End If
lrb = Cells(Rows.Count, 2).End(xlUp).Row
If Cells(lrb, 2).Value2 = "" And lrb = 1 Then
lrb = 0
ElseIf lrb = 1 Then
lrb = 1
End If
For i = 1 To row_bla
Cells(lrb + i, 2).Value2 = Cells(i, 1).Value2
Next
End Sub
 
Upvote 0
Another option
Sub FillBlanks()
Range("B:B").SpecialCells(xlBlanks).Value = Range("B" & Rows.Count).End(xlUp).Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,787
Messages
6,126,901
Members
449,348
Latest member
Rdeane

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