I have to open several files and then combine them together. What i am working on right now is when i open the file i have to parse the file name as it contains information that is specific to that file only. Also, its what i will use to differentiate the files once i put them all together.
I am enclosing an example of the file.
The file names are similar to the following:
Dav 101-20070611_16Jun2011.xlsx
What i would like is to parse this "Dav 101-20070611" and then store this into the file into a single column filling it down for as many rows are in the file. Not sure how to "efficiently" do this.
The text before the "_date" can be just about any combination of characters.
Last edited by welchs101; 07-01-2011 at 09:41 AM.
HI,
Here is some code that you may be able to use.
It goes down column A of sheet1 and then splits out the text and sends it to column A of sheet2.
Sub test() Dim cel As Range Dim lrow As Long Dim MyTxt As String Dim MyNewtxt As String For Each cel In Sheets("Sheet1").Range("A2:A" & Sheets("Sheet1").Range("A65536").End(xlUp).Row) MyTxt = Sheets("Sheet1").Cells(cel.Row, 1).Text MyNewtxt = Split(MyTxt, "_")(0) lrow = Sheets("Sheet2").Range("A65536").End(xlUp).Row + 1 Sheets("Sheet2").Range("A" & lrow).Value = MyNewtxt Next End Sub
Charles
There are other ways to do this, this is but 1 !
Be Sure you thank those who helped.
IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.
thanks i will check this out tomorrow andlet you know if it works for me.
thanks.
charles, turns out i took split function part of what you sent and then came up with the othe stuff. So thanks.
here is what i ended up with. Its not the most efficient but it works.
Note: I have a function which i probably should get rid of since i have now seen easier ways to find the last row since coming on this site. Function's name is lastrow.
Set myinputfile = Workbooks("Dav 101-20070611_16Jun2011.xlsx").Worksheets("Sheet1") junk1 = "Dav 101-20070611_16Jun2011.xlsx" MsgBox (junk1) Junk2 = Split(junk1, "_")(0) MsgBox (Junk2) myinputfile.Columns("A:A").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove lst_row = lastrow(1, 2, "Dav 101-20070611_16Jun2011.xlsx", "Sheet1", "up") myinputfile.Cells(1, 1).Value = "Protocol" myinputfile.Cells(2, 1).Value = Junk2 myinputfile.Range("A2:A" & lst_row).FillDown
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks