Consulting

Results 1 to 6 of 6

Thread: How do you create a VBA formula code based on Filename?

  1. #1

    How do you create a VBA formula code based on Filename?

    I have a match index formula that will look up data from another file, but the filename changes everyweek.

    How will I create a VBA formula code if filename changes?

    Below is my sample formula line, usually only the date on the filename changes (highlighted in red").

    [vba]Range("A7:A" & lRow).Formula = "=INDEX('G:\SCP\Consolidated\Product Supply Report\2010\Export Product Supply\Malaysia\[CAMPAIGNLY MAJOR OFFER SUPPORTABILITY_CFT_062310.xls]PSR'!H$7:H$65536,MATCH($F1,'G:\SCP\Consolidated\Product Supply Report\2010\Export Product Supply\Malaysia\[CAMPAIGNLY MAJOR OFFER SUPPORTABILITY_CFT_062310.xls]PSR'!$F$7:$F$65536,))"[/vba]

  2. #2
    VBAX Regular
    Joined
    Oct 2004
    Location
    Belgium
    Posts
    25
    Location
     
    dim strDay as string
    strDay = "062310" Range("A7:A" & lRow).Formula = "=INDEX('G:\SCP\Consolidated\Product Supply Report\2010\Export Product Supply\Malaysia\[CAMPAIGNLY MAJOR OFFER SUPPORTABILITY_CFT_" & strDay & ".xls]PSR'!H$7:H$65536, MATCH($F1,'G:\SCP\Consolidated\Product Supply Report\2010\Export Product Supply\Malaysia\[CAMPAIGNLY MAJOR OFFER SUPPORTABILITY_CFT_" & strDay & ".xls]PSR'!$F$7:$F$65536,))"


    Use a string variable and create a script to calculate the day.

    Hope this gives you an idea.

  3. #3
    Can I do
    strDay = range("A1") ???

  4. #4
    VBAX Regular
    Joined
    Oct 2004
    Location
    Belgium
    Posts
    25
    Location
    Yes that should work:

     
    strDay = range("A1").value
    You should test it.
    Let me know the outcome.

  5. #5
    Thanks! I'll let you know what happened when I finish my project!


    Thanks again!!!

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Please use line breaks _
    in long lines of text.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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