VBA - If cell in column B is blank then copy and paste it to column A

barclay34

New Member
Joined
Oct 21, 2014
Messages
21
Hello, need your help.

I need VBA

If cell in column B is blank then copy and paste it to column A

or

If cell in column B is blank then cell in column A should be blank too

Thank you.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Re: Need Help!!! VBA Help - If cell in column B is blank then copy and paste it to column A

If cell in column B is blank then copy and paste it to column A
Do you mean to say "NOT blank" for that first condition?

If so, then isn't really just a matter of copying all of column B to column A?
If so, turn on the Macro Recorder and record yourself doing this manually and you will have VBA code that will do this.
 
Upvote 0
Re: Need Help!!! VBA Help - If cell in column B is blank then copy and paste it to column A

If cell in column B is BLANK (empty), then cell in column A should be also BLANK (empty)

If cell in column B is not BLANK, then it stays as it was
 
Upvote 0
Re: Need Help!!! VBA Help - If cell in column B is blank then copy and paste it to column A

Try this:
Code:
Sub MyMacro()

    Dim lastRow As Long
    Dim myRow As Long
        
    Application.ScreenUpdating = False
    
'   Find last row with data in column A
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Loop through all rows
    For myRow = 1 To lastRow
        If Cells(myRow, "B") = "" Then Cells(myRow, "A").ClearContents
    Next myRow
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Re: Need Help!!! VBA Help - If cell in column B is blank then copy and paste it to column A

Thank you very much !!!
 
Upvote 0
Re: Need Help!!! VBA Help - If cell in column B is blank then copy and paste it to column A

You are welcome.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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