concatenate cells

eran3185

Board Regular
Joined
Apr 28, 2007
Messages
142
Hi ,

i have a colume a with data
I have colume b with numbers :1 or 2

I want to do this thing :
If i have in cells b1-b3 the value 1 and in cell b4 the value 2 , i want to concatenate a1-a3 and paste it into c1
If i have in cells b5 - b9 the value 1 and b10 the value 2 , i want to concatenate b5-b9 and paste into c2
If i have in cells b11-b22 the value 1 and b23 the value 2 , i want to concatenate b11-b22 and paste into c3 etc...

Is there a macro for this ?


thanks
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Concatenate is normally only used for text not numbers. If you do this your result will be looked at as text and not a number. Are you sure this is what you want? So C1 will look like this "111"
 
Upvote 0
You did not say what delimiter to use between concatenated values, so I assume a comma followed by a space (see red highlighted text)...
Code:
Sub ConcatColumnAifColumnBhasOneInIt()
  Dim R As Long, Ar As Range
  Columns("B").Replace 1, "=1", xlWhole
  For Each Ar In Columns("B").SpecialCells(xlFormulas).Areas
    R = R + 1
    If Ar.Count = 1 Then
      Cells(R, "C").Value = Ar.Offset(, -1).Value
    Else
      Cells(R, "C").Value = Join(Application.Transpose(Ar.Offset(, -1)), [B][COLOR="#FF0000"]", "[/COLOR][/B])
    End If
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,507
Messages
6,114,029
Members
448,543
Latest member
MartinLarkin

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