Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 06-08-2008, 07:01 PM
durandal05 durandal05 is offline
Registered User
 
Join Date: 03 May 2008
Posts: 57
durandal05 is becoming part of the community
I need to format various strings (numbers, dates) precisely

Please Register to Remove these Ads

I have a few fields where I need the resulting string to have a fixed number of digits

For instance,
I need text entered as '71' to become '071'
And i need a date like '01/4/2008' to become '010408'
And other numbers, like '5' must become '5.00'

If anyone knows how to handle any of the above, I'd really appreciate being pointed in the right direction.
Reply With Quote
  #2  
Old 06-08-2008, 07:37 PM
rylo rylo is offline
Forum Moderator
 
Join Date: 15 Jan 2007
Location: Brisbane, Australia
MS Office Version:2003
Posts: 4,096
rylo is very confident of their ability rylo is very confident of their ability rylo is very confident of their ability rylo is very confident of their ability
Hi

How do you know if a number (71) is to be formatted 071 or 71.00???

And is the formatting just for display, or does the result have to be in that structure?

rylo
Reply With Quote
  #3  
Old 06-08-2008, 08:10 PM
durandal05 durandal05 is offline
Registered User
 
Join Date: 03 May 2008
Posts: 57
durandal05 is becoming part of the community
I am feeding data into another program, and it demands that you type numbers in these strange formats

so if 70 was fed into the other program, it wouldn't work, it would have to be 070 (it's a really really old database program) for it to accept the input

i just need code that will take strings in VBA and format them like this
sometimes i need it to add zeros to make the string a certain length, other times i need to add 2 decimal places, other times i need the date in 6 digit format
Reply With Quote
  #4  
Old 06-09-2008, 08:22 AM
durandal05 durandal05 is offline
Registered User
 
Join Date: 03 May 2008
Posts: 57
durandal05 is becoming part of the community
ok I got the dates working

Code:
Private Sub cmbDate_Click()
Me.cmbDate.value=Format("ddmmyy")
End Sub
it came up with a 'object not in library' error which i fixed by going to tools>references and unchecking the 'Missing' directories

still stumped with making numbers into 3 digits like '55' to '055'
Reply With Quote
  #5  
Old 06-09-2008, 09:28 AM
Wskip49 Wskip49 is offline
Forum Contributor
 
Join Date: 08 Mar 2007
Posts: 139
Wskip49 is becoming part of the community
Custom Formatting

Can't this be done under Cell Format, Custom Formatting?
Reply With Quote
  #6  
Old 06-10-2008, 08:55 PM
rylo rylo is offline
Forum Moderator
 
Join Date: 15 Jan 2007
Location: Brisbane, Australia
MS Office Version:2003
Posts: 4,096
rylo is very confident of their ability rylo is very confident of their ability rylo is very confident of their ability rylo is very confident of their ability
Hi

If you want a number to have a leading 0, then you have to make the cell text. You can either change the cell format, or put a ' before the number.

As I asked earlier, how is the macro to know if a number is being changed to have a leading 0, or to have trailing decimal places?

rylo
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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

Forum Jump