Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
PADDING STRINGS !!!!!
Hello -
Arr1() contains strings. When I unload them into my sheet (one index Arr1()content per cell), I would like for all the single digits to be padded with a zero. For example, "1" should show as "01", "5" as "05", e.t.c.. Any help would be appreciated. Thanks Jay Dean *** Sent via Developersdex http://www.developersdex.com *** |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
PADDING STRINGS !!!!!
You could keep the values numeric and format the cell with a custom format: 00
Or you could format the cells as Text and plop them in as text. Option Explicit Sub testme01() Dim myArr As Variant Dim myCell As Range myArr = Array(1, 2, 12, 25) Set myCell = ActiveSheet.Range("A1") With myCell.Resize(UBound(myArr) - LBound(myArr) + 1, 1) .NumberFormat = "00" .Value = Application.Transpose(myArr) End With End Sub or Option Explicit Sub testme02() Dim myArr As Variant Dim myCell As Range Dim iCtr As Long Dim myOffset As Long myArr = Array(1, 2, 12, 25) Set myCell = ActiveSheet.Range("A1") With myCell.Resize(UBound(myArr) - LBound(myArr) + 1, 1) .NumberFormat = "@" 'text End With myOffset = 0 For iCtr = LBound(myArr) To UBound(myArr) myCell.Offset(myOffset, 0).Value = Format(myArr(iCtr), "00") myOffset = myOffset + 1 Next iCtr End Sub jay dean wrote: Hello - Arr1() contains strings. When I unload them into my sheet (one index Arr1()content per cell), I would like for all the single digits to be padded with a zero. For example, "1" should show as "01", "5" as "05", e.t.c.. Any help would be appreciated. Thanks Jay Dean *** Sent via Developersdex http://www.developersdex.com *** -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
PADDING STRINGS !!!!!
Thanks Dave, and Blue Max !
That's exactly what I wanted. Jay Dean *** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
find and replace numeric strings in larger text strings | Excel Worksheet Functions | |||
padding ? | Excel Discussion (Misc queries) | |||
How to find number of pairs of strings from list of strings? | Excel Worksheet Functions | |||
Value padding in VBA | Excel Programming |