Concatenate VBA in Reverse Order

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
961
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Bill Jelen has a Mr Excel video that has the following code

Function ConcatenateRange(rCells As Range)
Dim vTemp As Variant
Application.Volatile

For Each vTemp In rCells
ConcatenateRange = ConcatenateRange & vTemp & " "
Next vTemp
End Function

If I currently have a cell range from A20 through A26 which is what I have now.
Is it possible to change the code where it concatenates cell A26 1st then A25, A24, A23, A22, A21, A20?
Thanks in advance!!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Noting the code you posted output a text string with a trailing space. Keeping that trailing space, but outputting in the order you asked for, just replace the line of code inside the For..Next loop with this one...

ConcatenateRange = vTemp & " " & ConcatenateRange

If you do not want the trailing space, you will need another line of code that TRIM's ConcatenateRange after the loop.
 
Upvote 0
I did find a minor error when using the update line of code
This line works when calculating the concatenated text.
The text can be any combination of "x" and "dashes" ( -) from a range of 5 cells such as A1 through E1
ConcatenateRange = ConcatenateRange & vTemp & " "

The updated code below gives me the same but for some reason the concatenated result with the "x" and dashes (-) can not work with any other formulas to count patterns of x's and dashes.
ConcatenateRange = vTemp & " " & ConcatenateRange

Thanks in advance.
 
Upvote 0
Ok disregard the previous post. I made an error in the changes.
Thank you again Rick!!
Sorry for the post
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,122,998
Members
449,092
Latest member
masterms

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