Copy from column B if adjescent cell of Column A is empty

Mixture

New Member
Joined
Feb 18, 2015
Messages
24
Title says a nice brief summary.

I'm using a VBA Macro

It's for a party this Friday and some people entered their name in the wrong place.
I have two sheets, let's call them SourceSheet and DestinationSheet.
SourceSheet has 2 columns with the same information, I want to make them into one and put them in 1 column on DestinationSheet.
Example SourceSheet:
[TABLE="width: 100"]
<tbody>[TR]
[TD]Sam[/TD]
[TD]Sam[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Max[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Linda[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

What I want DestinationSheet to look like (I dont't believe I have any double-blanks however):
[TABLE="width: 100"]
<tbody>[TR]
[TD]Sam[/TD]
[/TR]
[TR]
[TD]Max[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]Linda[/TD]
[/TR]
</tbody>[/TABLE]

Except it are a few hundreds of names, so the use of a range would be nice, comments a huge plus too.
I would love to understand how it works.
Since I want to use this sheet for the next party I'm giving a macro would be good.
And I believe the cells aren't "blank blank" since I gave them the 'cell.value= "" '

I have tried plenty and searched for 2 days now, can't find anything close.
So go wild, go nuts. If you need to use columns as palceholders go ahead since I couldn't even figure it out when I got them all on one sheet.

Questions are welcome, any help would be appreciated.
I'm going to continue googling to solve the problem, and will of course report back if I find it before anyone else.
Thanks advance!
 
Last edited:
Welcome to the board..

In Destination sheet, say A2 (assuming row 1 is headers in both sheets)

=IF('SourceSheet'!A2="",'SourceSheet'!B2,'SourceSheet'!A2)

And fill down.
 
Upvote 0
Welcome to the board..
Thank you very much.
Long time lurker, first time poster :-)

I completely forgot to say that I'm creating a macro, so a code would be most handy.
I will keep your solution in the back of my head for when things don't work out.

Thanks for your help!
 
Upvote 0
I'm still looking for a VBA Excel Macro to do it.
If I ever get it working I'll report and post it here :-)
 
Upvote 0
Here's one way

Code:
Sub test()
Dim Src As Worksheet, Dst As Worksheet
Dim MyRange As Range, c As Range, i As Long
Set Src = Sheets("SourceSheet")
Set Dst = Sheets("DestinationSheet")

Set MyRange = Intersect(Src.UsedRange, Src.Range("A:A"))
i = 1
For Each c In MyRange
    If c.Value = "" Then
        Dst.Cells(i, "A").Value = c.Offset(0, 1).Value
    Else
        Dst.Cells(i, "A").Value = c.Value
    End If
    i = i + 1
Next c
End Sub
 
Upvote 0
Here's one way

Code:
Sub test()
Dim Src As Worksheet, Dst As Worksheet
Dim MyRange As Range, c As Range, i As Long
Set Src = Sheets("SourceSheet")
Set Dst = Sheets("DestinationSheet")

Set MyRange = Intersect(Src.UsedRange, Src.Range("A:A"))
i = 1
For Each c In MyRange
    If c.Value = "" Then
        Dst.Cells(i, "A").Value = c.Offset(0, 1).Value
    Else
        Dst.Cells(i, "A").Value = c.Value
    End If
    i = i + 1
Next c
End Sub

You are absolutely Amazing.
But I think you already knew that.
You just saved me hours of work!
 
Upvote 0

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