+ Reply to Thread
Results 1 to 14 of 14

Thread: Incremental naming in cells by file and date

  1. #1
    Registered User
    Join Date
    03-07-2011
    Location
    Madison, wisconsin
    MS-Off Ver
    Excel 2003
    Posts
    15

    Incremental naming in cells by file and date

    I have a path example of ='\\example\[1.1_filename.xlsx]sheet'!I3 that I need to paste horizontally in each cell in a row as:

    ='\\example\[1.1_filename.xlsx]sheet'!I3
    ='\\example\[1.2_filename.xlsx]sheet'!I3
    ='\\example\[1.3_filename.xlsx]sheet'!I3
    ='\\example\[1.4_filename.xlsx]sheet'!I3
    ='\\example\[1.5_filename.xlsx]sheet'!I3
    etc..... to 1.31

    Additionally, I need to paste each of those vertically in a columns as:
    ='\\example\[1.1_filename.xlsx]sheet'!I3

    down to:

    ='\\example\[1.1_filename.xlsx]sheet'!I12


    There has to be an easier way to do this than changing the date by hand in each cell?

    Any help is appreciated!

    -Mike

  2. #2
    Valued Forum Contributor tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2003 - 2007
    Posts
    2,352

    Re: Incremental naming in cells by file and date

    Mike,

    In cell A1, try this formula:
    =INDIRECT("'\\example\[1."&MOD(ROW()-1,31)+1&"_filename.xlsx]sheet'!I"&INT((ROW()-1)/31)+3)
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    03-07-2011
    Location
    Madison, wisconsin
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Incremental naming in cells by file and date

    Hmmm it's giving me a reference error, but still going through it.

  4. #4
    Valued Forum Contributor tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2003 - 2007
    Posts
    2,352

    Re: Incremental naming in cells by file and date

    You'll have to change the path, filename, and sheetname. Also, the formula will not work properly if it does not start in row 1.

    EDIT: After testing, it looks like the formula only works properly when the referenced workbook(s) are open...
    Last edited by tigeravatar; 01-20-2012 at 03:11 PM.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Valued Forum Contributor tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2003 - 2007
    Posts
    2,352

    Re: Incremental naming in cells by file and date

    Mike,

    This macro will accomplish what you're looking for.

    How to use a macro:
    1. Make a copy of the workbook the macro will be run on
      • Always run new code on a workbook copy, just in case the code doesn't run smoothly
      • This is especially true of any code that deletes anything
    2. In the copied workbook, press ALT+F11 to open the Visual Basic Editor
    3. Insert | Module
    4. Copy the provided code and paste into the module
    5. Close the Visual Basic Editor
    6. In Excel, press ALT+F8 to bring up the list of available macros to run
    7. Double-click the desired macro (I named this one IncrementFileLink)
    Sub IncrementFileLink()
        
        Const strDirectory As String = "\\example\"
        Const strFileName As String = "filename"
        Const strSheetName As String = "sheet"
        
        Dim i As Long
        For i = 1 To 310
            Cells(i, "A").Formula = "=" & Evaluate("=""'" & strDirectory & "[1.""&MOD(" & i & "-1,31)+1&""_" & strFileName & ".xlsx]" & strSheetName & "'!I""&INT((" & i & "-1)/31)+3")
        Next i
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  6. #6
    Registered User
    Join Date
    03-07-2011
    Location
    Madison, wisconsin
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Incremental naming in cells by file and date

    Thank you sooo much!!!! Sooo close!! Right now it checks all the files, gets the data, etc... but adds all of the data to column A1. Is there a way to break them by row?

    ='\\example\[1.1_filename.xlsx]sheet'!I3 (starting at A1)
    ='\\example\[1.2_filename.xlsx]sheet'!I3 (..........A2)
    ='\\example\[1.3_filename.xlsx]sheet'!I3 (A3.....)
    ='\\example\[1.4_filename.xlsx]sheet'!I3 (A4)
    ='\\example\[1.5_filename.xlsx]sheet'!I3
    etc..... to 1.31

    Thanks again!!

    -Mike
    Last edited by evilgrinners; 01-20-2012 at 04:29 PM. Reason: notify added

  7. #7
    Valued Forum Contributor tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2003 - 2007
    Posts
    2,352

    Re: Incremental naming in cells by file and date

    I don't understand, isn't the macro doing that already? Do you mean you want to split it up into different columns?
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  8. #8
    Registered User
    Join Date
    03-07-2011
    Location
    Madison, wisconsin
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Incremental naming in cells by file and date

    I'm sorry, I'm not explaining it right.

    Right now it collects all of the months data and puts it all into Column A1, but I actually need the data from each day put into a seperate column.

    So, an example would be...

    collect data from ='\\example\[1.1_filename.xlsx]sheet'!I3 ( collect data from I3 to I12 and put it in column A1)
    collect data from ='\\example\[1.2_filename.xlsx]sheet'!I3 ( collect data from I3 to I12 and put it in column A2)
    collect data from ='\\example\[1.3_filename.xlsx]sheet'!I3 ( collect data from I3 to I12 and put it in column A3)
    Etc... all the way to Jan 31st (1.1 - 1.31)

    Hopefully that makes more sense?

    Thank you!

    -Mike

  9. #9
    Valued Forum Contributor tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2003 - 2007
    Posts
    2,352

    Re: Incremental naming in cells by file and date

    Mike,

    I'm pretty sure you want one of these two, but I don't know which, so here's both:

    Sub IncrementFileLink2()
        
        Const strDirectory As String = "\\example\"
        Const strFileName As String = "filename"
        Const strSheetName As String = "sheet"
        
        Dim r As Long
        Dim c As Long
        Dim i As Long
        
        For c = 1 To 10
            For r = 1 To 31
                i = i + 1
                Cells(r, c).Formula = "=" & Evaluate("=""'" & strDirectory & "[1.""&MOD(" & i & "-1,31)+1&""_" & strFileName & ".xlsx]" & strSheetName & "'!I""&INT((" & i & "-1)/31)+3")
            Next r
        Next c
        
    End Sub


    Sub IncrementFileLink3()
        
        Const strDirectory As String = "\\example\"
        Const strFileName As String = "filename"
        Const strSheetName As String = "sheet"
        
        Dim r As Long
        Dim c As Long
        Dim i As Long
        
        For r = 1 To 10
            For c = 1 To 31
                i = i + 1
                Cells(r, c).Formula = "=" & Evaluate("=""'" & strDirectory & "[1.""&MOD(" & i & "-1,31)+1&""_" & strFileName & ".xlsx]" & strSheetName & "'!I""&INT((" & i & "-1)/31)+3")
            Next c
        Next r
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  10. #10
    Registered User
    Join Date
    03-07-2011
    Location
    Madison, wisconsin
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Incremental naming in cells by file and date

    A million thank you's!!! You are awesome! EXACTLY what I needed!!!

  11. #11
    Registered User
    Join Date
    03-07-2011
    Location
    Madison, wisconsin
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Incremental naming in cells by file and date

    One quick follow-up and I'll shut-up, promise.

    If I wanted to start pasting that info starting in a specific cell besides A1, would that be difficult? Example would be if I needed to start pasting it in like..... D4, as an example?

    Thanks!

  12. #12
    Valued Forum Contributor tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2003 - 2007
    Posts
    2,352

    Re: Incremental naming in cells by file and date

    in the code, r is the row number and c is the column number. A1 is row 1, column 1. If you needed it to start in D4 (which is row 4, column 4), you would change the Cells(r, c)... line to be Cells(r + 3, c + 3)....

    To start in E2 (which is row 2, column 5), you would use:
    Cells(r + 1, c + 4).Formula = ...
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  13. #13
    Registered User
    Join Date
    03-07-2011
    Location
    Madison, wisconsin
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Incremental naming in cells by file and date

    Thank you!

  14. #14
    Valued Forum Contributor tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2003 - 2007
    Posts
    2,352

    Re: Incremental naming in cells by file and date

    EDIT: Ack! double-post due to database error
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

+ 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