Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
find and replace numeric strings in larger text strings Mr Molio Excel Worksheet Functions 8 November 9th 11 05:17 PM
padding ? vbastarter Excel Discussion (Misc queries) 2 March 7th 06 12:11 PM
How to find number of pairs of strings from list of strings? greg_overholt Excel Worksheet Functions 5 January 27th 06 10:42 PM
Value padding in VBA raj Excel Programming 2 December 14th 03 09:51 PM


All times are GMT +1. The time now is 05:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"