+ Reply to Thread
Results 1 to 4 of 4

Thread: Parse file name and put parsed value into file

  1. #1
    Forum Guru
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2007
    Posts
    1,252

    Parse file name and put parsed value into file

    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.
    Attached Files Attached Files
    Last edited by welchs101; 07-01-2011 at 09:41 AM.

  2. #2
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    657

    Re: Parse file name and put parsed value into file

    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.

  3. #3
    Forum Guru
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2007
    Posts
    1,252

    Re: Parse file name and put parsed value into file

    thanks i will check this out tomorrow andlet you know if it works for me.

    thanks.

  4. #4
    Forum Guru
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2007
    Posts
    1,252

    Re: Parse file name and put parsed value into file

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0