Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
No question here, just an Excel VBA procedure for the archive.
Search Criteria: Add leading zeros to number, cell value, lead cell value with zeros, precede value with zero, add zero before value, and concatenate number with zero Sub LeadingZeroAddPrompt() 'Prompts user and adds the leading zeros to cell value for all 'cells in selection. Note this procedure must format values as TEXT 'for the procedure to work properly. Dim v As Integer On Error Resume Next v = InputBox("Enter # of zeros to add to front. Five (5) is the most you can add.", "Add Leading Zeros") If v = 1 Then For Each cell In Selection cell.NumberFormat = "@" cell.Value = "0" & cell.Value Next cell End If If v = 2 Then For Each cell In Selection cell.NumberFormat = "@" cell.Value = "00" & cell.Value Next cell End If If v = 3 Then For Each cell In Selection cell.NumberFormat = "@" cell.Value = "000" & cell.Value Next cell End If If v = 4 Then For Each cell In Selection cell.NumberFormat = "@" cell.Value = "0000" & cell.Value Next cell End If If v = 5 Then For Each cell In Selection cell.NumberFormat = "@" cell.Value = "00000" & cell.Value Next cell End If End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Limiting selection in a cell AND linking that selection to a list | Excel Discussion (Misc queries) | |||
Range of Values with different column selection | Excel Discussion (Misc queries) | |||
Formatting cell based upon values w/in a selection | New Users to Excel | |||
sequential numbering of zero leading values | Excel Discussion (Misc queries) | |||
Leading Zeros in Numeric Values | Excel Worksheet Functions |