Trouble Merging Cells

colbertja

New Member
Joined
Feb 20, 2013
Messages
3
I need some assistance in combining multiple cells into one and keeping the formatting the same. I currently have code that will combine the columns but it losses the leading zero on numbers less than 10. For instance I gave some examples of the current output.

CURRENT
[TABLE="width: 500"]
<tbody>[TR]
[TD]Hour[/TD]
[TD]Min[/TD]
[TD]Sec[/TD]
[TD]Result[/TD]
[/TR]
[TR]
[TD]09[/TD]
[TD]53[/TD]
[TD]23[/TD]
[TD]9'53'23[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]42[/TD]
[TD]06[/TD]
[TD]10'42'6[/TD]
[/TR]
[TR]
[TD]16[/TD]
[TD]00[/TD]
[TD]45[/TD]
[TD]16'0'45[/TD]
[/TR]
</tbody>[/TABLE]

DESIRED
[TABLE="width: 500"]
<tbody>[TR]
[TD]Hour[/TD]
[TD]Min[/TD]
[TD]Sec[/TD]
[TD]Result[/TD]
[/TR]
[TR]
[TD]09[/TD]
[TD]53[/TD]
[TD]23[/TD]
[TD]09'53'23[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]42[/TD]
[TD]06[/TD]
[TD]10'42'06[/TD]
[/TR]
[TR]
[TD]16[/TD]
[TD]00[/TD]
[TD]45[/TD]
[TD]16'00'45[/TD]
[/TR]
</tbody>[/TABLE]


Below is a copy of the current code that I am using that will combine the columns it just will not continue the leading zero. I am pretty sure the issue is when I do the actual combining I am using "cell.Value" and it is not keeping the values. I want to either find a way to treat the range of cells as a string or keep the number formatting when I combine the three cells.


Function CombineColumn(myRange As Range)


Dim cell As Range
For Each cell In myRange
If Len(cell) > 0 Then
CombineColumn = CombineColumn & cell.Value & "'"
End If
Next cell

If Len(CombineColumn) > 0 Then
CombineColumn = Left(CombineColumn, Len(CombineColumn) - 1)
Else
CombineColumn = ""
End If

End Function


-Thanks in advance
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Change Cell.Value to Cell.Text.
 
Upvote 0
Norie, that worked perfect! I thought it was something that simple but couldn't find it anywhere.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,930
Members
452,367
Latest member
TePunaBloke

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