Concatenate 2 columns into 1 column with seperator

STEEL010

Board Regular
Joined
Dec 29, 2017
Messages
76
Hi There,

I'm trying to concatenate 2 columns ("A") and ("B") into 1 column ("A") with an ";" separator via VBA.
I have already have a code that doing stuff already and I want to add the concatenate function in to it, can somebody help?

all have to comeback into column A.


Sheets("Sheet2").Copy
Sheets("Sheet2").Range("A2:F101").Copy
Sheets("Sheet2").Range("A2").PasteSpecial Paste:=xlPasteValues
Sheets("Sheet2").Range("A1:H1").Delete Shift:=xlUp
Sheets("Sheet2").Range("C1:F101").Delete Shift:=xlToLeft
:eek:here I want the concatenate function:eek:


Greetings,
Steel010
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
This snippet will do that - note that ALL rows will have the semicolon inserted. If you want to ignore blank A and B rows, extra coding will be needed.
Code:
For i = 1 To 101
    Range("A" & i).Value = Range("A" & i).Value + ";" + Range("B" & i).Value
Next i
 
Upvote 0
dim cell as range
for each cell in Range("A2:A101")
cell.value= cell.value & ";" & cell.offset(0,1).value
next cell
 
Upvote 0
Another way
Code:
   With Range("A2:A101")
      .Value = Evaluate("if({1}," & .Address & "& ""; "" & " & .Offset(, 1).Address & ")")
   End With
 
Upvote 0
Fluff,

yours works, sorry jmacearly yours not, thanks anyway.

Fluff,

one thing .Address is that something I must change? because its doing its job but it let column B with value.

Another way
Code:
   With Range("A2:A101")
      .Value = Evaluate("if({1}," & .Address & "& ""; "" & " & .Offset(, 1).Address & ")")
   End With
 
Upvote 0
OK Steel thanks for the feedback - however it worked on my machine fine - could you tell me what 'didn't work'. If its because column B still has values, that is what seemed to be your request. If you want column B to be blank, then insert
Range("B" & i).Value="" in the loop.
 
Upvote 0
Do you want to clear the contents is col B, or delete the entire column?
 
Upvote 0
How about
Code:
Sub Steel010()
   With Range("A2:A101")
      .Value = Evaluate("if({1}," & .Address & "& ""; "" & " & .Offset(, 1).Address & ")")
   End With
   Columns(2).Delete
End Sub
 
Upvote 0
Fluff,

now nothing runs? and still it must be written following up my already written macro , not in with an extra sub.

is there a way
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,033
Members
448,940
Latest member
mdusw

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