Concatenate Range of Cells - Empty and Digits

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
814
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
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,562
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)
 

Watch MrExcel Video

Forum statistics

Threads
1,127,332
Messages
5,624,053
Members
416,007
Latest member
csf

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