VBA convert all single code numbers into 2 digits.

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Hello,

Column "D" how I have codes with single and double digits, i want a VBA which can covert all single digit into 2 digits as per result column E

Example file...


Book1
DE
1
2
3
4
5
6
7
8
9
10
11Orignal CodeRequired Result
126 | 4 | 4 + 10 | 0 | 0 - 0 | 0 | 106 | 04 | 04 + 10 | 00 | 00 - 00 | 00 | 01
136 | 4 | 4 + 10 | 0 | 0 - 0 | 0 | 206 | 00 | 00 + 10 | 00 | 00 - 00 | 00 | 02
146 | 4 | 4 + 11 | 0 | 0 - 0 | 0 | 306 | 04 | 04 + 11 | 00 | 00 - 00 | 00 | 03
156 | 5 | 3 + 0 | 0 | 1 - 0 | 0 | 1306 | 05 | 03 + 00 | 00 | 01 - 00 | 00 | 13
166 | 5 | 33 + 0 | 0 | 10 - 1 | 0 | 006 | 05 | 33 + 00 | 00 | 10 - 01 | 00 | 00
176 | 5 | 3 + 0 | 0 | 11 - 3 | 0 | 006 | 05 | 03 + 00 | 00 | 11 - 03 | 00 | 00
186 | 5 | 3 + 0 | 0 | 12 - 0 | 0 | 106 | 05 | 03 + 00 | 00 | 12 - 00 | 00 | 01
190 | 0 | 27 + 2 | 0 | 0 - 9 | 0 | 000 | 00 | 27 + 02 | 00 | 00 - 09 | 00 | 00
200 | 0 | 24 + 3 | 0 | 0 - 0 | 0 | 100 | 00 | 24 + 03 | 00 | 00 - 00 | 00 | 01
210 | 0 | 18 + 3 | 0 | 0 - 0 | 0 | 1000 | 00 | 18 + 03 | 00 | 00 - 00 | 00 | 10
220 | 0 | 84 + 3 | 0 | 0 - 0 | 0 | 6400 | 00 | 84 + 03 | 00 | 00 - 00 | 00 | 64
230 | 0 | 19 + 3 | 0 | 0 - 0 | 0 | 200 | 00 | 19 + 03 | 00 | 00 - 00 | 00 | 02
240 | 0 | 37 + 3 | 0 | 0 - 0 | 0 | 300 | 00 | 37 + 03 | 00 | 00 - 00 | 00 | 03
250 | 0 | 54 + 3 | 0 | 0 - 0 | 0 | 400 | 00 | 54 + 03 | 00 | 00 - 00 | 00 | 04
260 | 0 | 36 + 3 | 0 | 0 - 0 | 0 | 500 | 00 | 36 + 03 | 00 | 00 - 00 | 00 | 05
276 | 5 | 3 + 0 | 0 | 1 - 0 | 0 | 1206 | 05 | 03 + 00 | 00 | 01 - 00 | 00 | 12
286 | 5 | 3 + 0 | 0 | 1 - 0 | 0 | 7706 | 05 | 03 + 00 | 00 | 01 - 00 | 00 | 77
296 | 5 | 3 + 0 | 0 | 1 - 0 | 0 | 206 | 05 | 03 + 00 | 00 | 01 - 00 | 00 | 02
306 | 5 | 3 + 0 | 0 | 1 - 0 | 0 | 306 | 05 | 03 + 00 | 00 | 01 - 00 | 00 | 03
312 | 6 | 6 + 2 | 0 | 0 - 7 | 0 | 002 | 06 | 06 + 02 | 00 | 00 - 07 | 00 | 00
322 | 6 | 6 + 2 | 0 | 0 - 8 | 0 | 002 | 06 | 06 + 02 | 00 | 00 - 08 | 00 | 00
332 | 6 | 6 + 2 | 0 | 0 - 9 | 0 | 002 | 06 | 06 + 02 | 00 | 00 - 09 | 00 | 00
342 | 6 | 6 + 3 | 0 | 0 - 0 | 0 | 102 | 06 | 06 + 03 | 00 | 00 - 00 | 00 | 01
352 | 6 | 6 + 3 | 0 | 0 - 0 | 0 | 1002 | 06 | 06 + 03 | 00 | 00 - 00 | 00 | 10
362 | 6 | 6 + 3 | 0 | 0 - 0 | 0 | 1102 | 06 | 06 + 03 | 00 | 00 - 00 | 00 | 11
372 | 6 | 6 + 3 | 0 | 0 - 0 | 0 | 202 | 06 | 06 + 03 | 00 | 00 - 00 | 00 | 02
382 | 6 | 6 + 3 | 0 | 0 - 0 | 0 | 302 | 06 | 06 + 03 | 00 | 00 - 00 | 00 | 03
392 | 6 | 6 + 3 | 0 | 0 - 1 | 0 | 002 | 06 | 06 + 03 | 00 | 00 - 01 | 00 | 00
402 | 6 | 6 + 3 | 0 | 0 - 99 | 0 | 002 | 06 | 06 + 03 | 00 | 00 - 99 | 00 | 00
412 | 6 | 6 + 3 | 0 | 0 - 19 | 0 | 002 | 06 | 06 + 03 | 00 | 00 - 19 | 00 | 00
422 | 6 | 6 + 3 | 0 | 0 - 2 | 0 | 002 | 06 | 06 + 03 | 00 | 00 - 02 | 00 | 00
Sheet99


Thank you all

Excel 2000
Regards,
Moti
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
This should get ya there..


Code:
Sub Double_Up()
    For i = 2 To Sheets("Sheet1").UsedRange.Rows.Count
        curStr = Split(Cells(i, 1))
        For t = LBound(curStr) To UBound(curStr)
            If IsNumeric(curStr(t)) And Len(curStr(t)) < 2 Then
                curStr(t) = "0" & curStr(t)
            End If
            curOutput = curOutput & curStr(t) & " "
        Next t
        Cells(i, 3) = rTrim(curOutput)
        curOutput = Empty
    Next i
End Sub
 
Last edited:
Upvote 0
Solution
This should get ya there..


Code:
Sub Double_Up()
    For i = 2 To Sheets("Sheet1").UsedRange.Rows.Count
        curStr = Split(Cells(i, 1))
        For t = LBound(curStr) To UBound(curStr)
            If IsNumeric(curStr(t)) And Len(curStr(t)) < 2 Then
                curStr(t) = "0" & curStr(t)
            End If
            curOutput = curOutput & curStr(t) & " "
        Next t
        Cells(i, 3) = rTrim(curOutput)
        curOutput = Empty
    Next i
End Sub
Steve_, astutely amazing this is what I wanted, thank you for your help</SPAN></SPAN>
:beerchug:
Kind Regards,
</SPAN></SPAN>
Moti :-D
</SPAN></SPAN>
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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