Formula to Combine multiple columns into single cell

spectraflame

Well-known Member
Joined
Dec 18, 2002
Messages
829
Office Version
  1. 365
Platform
  1. Windows
Currently I am using the following formula to combine values from various columns into a single cell. The sheet is only capable of using columns A through Y but not all are required.

Range("Z1").Select
ActiveCell.FormulaR1C1 = _
"=RC[-25]&"",""&RC[-24]&"",""&RC[-23]&"",""&RC[-22]&"",,,""&RC[-19]&"",""&RC[-18]&"",""&RC[-17]&"",,,,""&RC[-13]&"",""&RC[-12]&"",""&RC[-11]&"",""&RC[-10]&"",,""&RC[-8]&"",,""&RC[-6]&"",""&RC[-5]&"",""&RC[-4]&"",,,"""
LR = ActiveSheet.UsedRange.Rows.Count
Range("Z1").AutoFill Destination:=Range("Z1:Z" & LR)

The columns on referenced in my current formula that are blank are skipped in the formula because I am not populating them at this time. However my concern is if there is a need to populate them in the future, I will have to manually change the formula to combine them correctly.

Does anyone have any suggestions on how to make this process more intelligent to include the columns if they are populated or just insert a "," if they are blank?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
you could create a UDF (User Defined Function) in VBA:
Code:
Function myConcat(rng As Range)
Dim cl As Range
For Each cl In rng
    myConcat = myConcat & IIf(cl = "", ",", cl.value & ",")
Next cl
myConcat = Left(myConcat, Len(myConcat) - 1)
End Function
and then use this in Excel as your formula
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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