Concatenate Range of Cells - Empty and Digits

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
974
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hello everyone,

Excel 2010 version of Excel

I searched and found the following code at "Extendoffice". See Below
It does everything required but the formula will not add leading zero (if required) in the concatenated set of 4 digit values from 0 through 9 even if I format the cells as "0000".

Each cell range contains 16 cells.
Each cell range can only contain 4 digits 0 through 9 and they can repeat.

Thank you in advance!!

Function Concatenatecells(ConcatArea As Range) As String
'updateby Extendoffice
For Each n In ConcatArea: nn = IIf(n = "", nn & "", nn & n & ""): Next
Concatenatecells = Left(nn, Len(nn) - 1)
End Function
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Formatting cells only changes their appearance, not their contents.

There are a few ways you can ensure your entries are exactly 4 digits long:

1. Convert the entry to a number (value), then apply the FORMAT function in VBA to it, i.e.
Format(yourString + 1,"0000")
See: MS Excel: How to use the FORMAT Function with Strings (VBA)

2. Concatenated 4 "0"s on to the front, and then take the 4 right-most characters, i.e.
Right("0000" & yourString,4)
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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