using concatenate in a macro to combine 2 cells with an ampersand between

alabing

New Member
Joined
Jul 25, 2012
Messages
3
column A contains the husband's name
column C contains the wife's name

If they both have the same last name (columns C and D) then column F contains "same last name"

So if they have the same last name, I want to combine the husband's and wife's first names with an ampersand between them and have that be in column E

I tired this:
Lastrow = Range("A65536").End(xlUp).Row
For x = Lastrow To 1 Step -1
If Range("f" & x).Value = "same last name" Then
Range("e" & x).Select
ActiveCell.Formula = _
"=concatenate("a" & x &" & " & "c" & x)"
End If
Next x
I get an "expected end of statement" compile error with the "a" flagged red.

So I tried this:
Lastrow = Range("A65536").End(xlUp).Row
For x = Lastrow To 1 Step -1
If Range("f" & x).Value = "same last name" Then
Range("e" & x).Select
ActiveCell.Formula = _
"=concatenate(a & x &" & " & c & x)"
End If
Next x
No error but when the macro ran, column e was blank

I tired:
Lastrow = Range("A65536").End(xlUp).Row
For x = Lastrow To 1 Step -1
If Range("f" & x).Value = "same last name" Then
Range("e" & x).Select
ActiveCell.Formula = _
"=concatenate(a & x, c & x)"
End If
Next x
No error but I got "0's" in column E.

Thanks,

Bill Roberts
Cumming, GA
Excel 97 ( i think )
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Do your really need the formula (if so, why make a macro insert it when you can do that so easily on the sheet yourself)? If not, don't call out to the worksheet's Concatenate function, just use VB code to create the concatentation (also, you do not need to select cells in order to change their values, you can do it directly). So, instead of this...

Code:
Range("e" & x).Select
ActiveCell.Formula = _
"=concatenate(a & x &" & " & c & x)"
try this instead...

Code:
Cells(x, "E").Value = Cells(x, "A").Value & " & " & Cells(x, "C").Value
 
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,025
Members
452,542
Latest member
Bricklin

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