Parsing data from worksheet name

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Hi folks...

I have a routine where I open the latest .csv file in my folder. The file has a worksheet with the name:

Activity_05242011_135415_0689.csv

This name is in the string SrcWks

In VB code, I would like to parse out the date and write it to a cell and then parse out the time and write it to another cell.

In advance, thanks for the help.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi

Here's an option that you can adapt:

Code:
Sub Test()
Dim SrcWks As String
Dim vArr As Variant
 
SrcWks = "Activity_05242011_135415_0689.csv"
vArr = Split(SrcWks, "_")
 
Range("A1").NumberFormat = "yyyy-mm-dd"
Range("A1") = DateSerial(Right(vArr(1), 4), Left(vArr(1), 2), Mid(vArr(1), 3, 2))
 
Range("A2").NumberFormat = "hh:mm:ss"
Range("A2") = TimeValue(Format(vArr(2), "00\:00\:00"))
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top