My code is not converting some columns to number

maravig

Board Regular
Joined
Jul 16, 2014
Messages
61
Hello again,
I'm ready to pull my hair out. I have a user form where an end user can select a CSV file and then pick a tab from a drop down list and have that file appended to that tab. It works just fine. I have 3 columns that need to be 5 digits so 3 needs to be 00003. I have tried so many different combinations and nothing works. Here is my latest attempt which found elsewhere:

Code:
For Each c In Range("B:B")
    If c = "" Then GoTo nextc
    If IsCustom(c) Then
        c.Value = c.Value * 1
        c.NumberFormat = "00000"
    End If
    
nextc:
Next c

I'm willing to try anything.

Jeff
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Have you tried stepping through the code? My guess is that IsCustom() sub/function is not working like you intend it to, and it's skipping over the code that sets c.NumberFormat = "00000".
 
Upvote 0
Possibly try....

Rich (BB code):
Sub FiveDigits()
    Dim arr, x As Long
    With Range("B1", Range("B" & Rows.Count).End(xlUp))
        .NumberFormat = "@"
        arr = .Value
        For x = 1 To UBound(arr, 1)
            arr(x, 1) = Right("0000" & arr(x, 1), 5)
        Next x
        .Value = arr
    End With
End Sub

but obviously the result is text and not a real number.
 
Upvote 0
What does your IsCustom function do?

Can you post its code?
 
Upvote 0
That was interesting. I ran the code and it was processing. In the background, it actually showed up correct!. Then I noticed it saying "filling cells" in the bottom and it went back to its original state. Man, so close.
 
Upvote 0
I removed that code and am using Mark858's and that's the closest I've come to it working.
 
Upvote 0

Forum statistics

Threads
1,216,146
Messages
6,129,142
Members
449,488
Latest member
qh017

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