Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Spaces into a String

Status
Not open for further replies.

Craig9999

Technical User
Jun 18, 2003
7
EU
Hi Ladies and Gents,

I'm have a little style problem, and hope you can sort me out.

I have a PDF with a date field, I'm filling that field with data from FDF.

The text field for the date reads 20122003
However to fill the boxes in the right places the date has to read 2 0 1 2 2 0 0 3

Now you see my problem, somehow I need to read in the string and after so many chars insert spaces to align the numbers to the pdf boxes.

The data file is being created in excel, and to date I have over come many of my VBA problems, but this one is driving me crazy.

Please help

Craig

 
Here is a User Defined Function (UDF) that does what you want. (You can tweak the mask to adjust for more spaces if needed.)
[blue]
Code:
Sub test()
  MsgBox SpacedOutDate(20122003)
  MsgBox SpacedOutDate("20122003")
End Sub

Function SpacedOutDate(ADate) As String
Dim nDate As Long
  nDate = ADate
  SpacedOutDate = Format(nDate, "0 0  0 0  0 0 0 0")
End Function
[/color]

Note that it works with either a string or a number as input.
 
Cool.

Brillant off to play with this very helpful function.

Have a star.

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top