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. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > String manipulation using VBA

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-24-09, 15:19
raora02 raora02 is offline
Registered User
 
Join Date: Mar 2009
Posts: 1
String manipulation using VBA

Hi,

I have a spreadsheet using which I create a text file (using a macro). The spreadsheet has two columns with dates as strings in the format yyyymmdd. When I write to the text file, I want the dates to be written in the mmddyyyy format. What is the easiest way of doing this?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 03-25-09, 19:33
VBAExpert VBAExpert is offline
Registered User
 
Join Date: Mar 2009
Location: Worthing, UK
Posts: 16
hi

upload your sample file please..

Reagards
Reply With Quote
  #3 (permalink)  
Old 04-02-09, 21:12
savbill savbill is offline
Registered User
 
Join Date: Feb 2004
Posts: 533
You can use string functions to extract parts of the date then recombine them in the order you require. Since you are already using a VB Script Macro it would be practical to modify this to process the date strings.

Code:
' Use trim to remove leading and trailing spaces
strDate = Trim(Cells(i, 2))
strYr = Left(strDate, 4)
strMD = Right(strDate, 4)
strDate = strMD & strYr
You didn't show any slashes in your date but if there were it would make this task even easier, and more exacting. Here's a way of parsing the date with slash delimiters
Code:
' start with the string in a variable
' having date format of "yyyy/mm/dd"
strDate = Trim(Cells(i, 2))
arryDt = Split(strDate, "/")
strDate = arryDate(1)
strDate = strDate & "/" & arryDate(2)
strDate = strDate & "/" & arryDate(0)
' now the date will be in the variable with
' format of "mm/dd/yyyy"
__________________
~

Bill
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On