Concatenate Range of Cells - Empty and Digits

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
864
Office Version
  1. 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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,302
Office Version
  1. 365
Platform
  1. Windows
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)
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,012
Messages
5,834,923
Members
430,326
Latest member
tomwax46

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
Top