How to add zeros at the end

timpepu

Board Regular
Joined
Mar 4, 2008
Messages
89
Hi !

I have text like this 00000058 , I want add 0 so many times that it is 14 character long like this 00000058000000 .
How should I do it with VBA.

Br
Timo
 
Code:
Sub test()
Dim c As Range
For Each c In Range("B1:B" & Range("B" & Rows.Count).End(xlUp).Row)
    If Left(c.Offset(, -1),2) = "02" Then
        c.NumberFormat = "@"
        c = Format(c, String(8, "0")) & String(6, "0")
    End If
Next
End Sub
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Code:
Sub test()
Dim c As Range
For Each c In Range("B1:B" & Range("B" & Rows.Count).End(xlUp).Row)
    If Left(c.Offset(, -1),2) = "02" Then
        c.NumberFormat = "@"
        c = Format(c, String(8, "0")) & String(6, "0")
    End If
Next
End Sub


Sorry , it was the last one
 
Upvote 0
Are there any other conditions? I could then write the code once for all your conditions.


Thanks ,it works fine but one thing what I didn't told ,how should it be if this "02" is like 0233456788 examble and I want to check that only first two characters are 02 ?

Sorry ,this is the last one !!!!!


Br
Timo
 
Upvote 0

Forum statistics

Threads
1,216,058
Messages
6,128,539
Members
449,457
Latest member
ncguzzo

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