View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default adding leading zero in Excel

Very nice


Thank you for introducing me to JOIN()
--
Gary''s Student - gsnu200744


"Rick Rothstein (MVP - VB)" wrote:

I can solve this with visual basic.


I'll save you the trouble.<g

If there is only one leading letter character for each "field" in the cell
and if the number part always needs to be three digits long, then this sub
should work...

Sub AddZeroes()
Dim C As Range
Dim Fields() As String
For Each C In Selection
Fields = Split(C.Value, ",")
For X = 0 To UBound(Fields)
Fields(X) = Left$(Fields(X), 1) & _
Format$(Mid$(Fields(X), 2), "000")
Next
C.Value = Join(Fields, ",")
Next
End Sub

To ENFGDC4S:
=============
All you have to do is right-click the sheet tab at the bottom, and "View
Code"; then copy/paste the above routine into the sheet's code window. Once
you have done that, go back to the spreadsheet and select the cells you want
to apply this routine to and then press Alt+F8 and run the AddZeroes macro
from the dialog box that appears.

Rick