Concatenate Cell Range - Empty Cells

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hello,
I have a range of cell from A1 through F1
Values in this range can vary from 00 through 99
Cell G1 contains the formula that concatenates all the values from range A1 through F1
Random cells in A1 through F1 may be empty.
Each of the values will be separated by a coma.

I found the following code for a Functions that works but I'm looking for code that will keep the 1st zero when concatenating the range
If a cell contains any value for 00 though 09 I would like to keep the 1st zero.

Function ConcatenateButBlank(selectArea As Range) As String
For Each oneCell In selectArea: finalResult = IIf(oneCell = "", finalResult & "", finalResult & oneCell & ","): Next
ConcatenateButBlank = Left(finalResult, Len(finalResult) - 1)
End Function

Thank you in advance!!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I think this replacement for the function you are now using should do what you want...
VBA Code:
Function ConcatenateButBlank(selectArea As Range) As String
  ConcatenateButBlank = Replace(Application.Trim(Replace(" " & Join(Evaluate("TEXT(" & selectArea.Address & ",""00"")")) & " ", " 00 ", " ")), " ", ",")
End Function
Rick I tried entering in your code again but still getting the Values.
The cell range I have contains empty cells and some with values between 00 and 99.
Could the empty cell be the reason for the "Values"??
Thank you
 
Upvote 0
Rick I tried entering in your code again but still getting the Values.
The cell range I have contains empty cells and some with values between 00 and 99.
Could the empty cell be the reason for the "Values"??
Thank you
No, I tested with some blanks in the range A1:F1 and my code works fine for me. No matter, you have working code from Peter, so stick with that (I think his code is better than mine anyway).
 
Upvote 0
Thanks Rick.
I have 2 versions of Excel 2010 & 365.
You are correct. Your code works like a charm in 365 but not in 2010. I should have explained in the OP that the values were in a 2010 version.
Sorry about that.
Thank you again for all your help.
Very much appreciated
 
Upvote 0

Forum statistics

Threads
1,213,504
Messages
6,114,016
Members
448,543
Latest member
MartinLarkin

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