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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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,216,075
Messages
6,128,657
Members
449,462
Latest member
Chislobog

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