+ Reply to Thread
Results 1 to 11 of 11

Pass Variable in VB Code

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Pass Variable in VB Code

    Hello:

    I am using VB Macro Code attached to paste certain range of data from closed excelworkbook named
    "01_2013.xls" to current open excel file Called "2013_Yearly.xls", in sheet called "Jan13".

    "2013_Yearly.xls will have sheet for all 12 months, Jan13,Feb13,Mar13.....Dec13

    To do this I open 2013_Yealy.xls file and go to Jan13 tab and run the above macro and it works fine.

    I will have monthly .xls sheet as "02_2013", "03_2013", etc

    I want to see if it is possible to have the attached macro modified so that
    when i open 2013_Yearly.xls file and go to let us say Feb13 tab to run the above macro.
    Once i run the macro, the source file name in the code should automaticaly change to "02_2013.xls" for Feb and destination should change to Feb13 in the code
    Basically i wan to use one macro to perform for all 12 months rather then creating macro for each month.

    I hope this is clear and looking forward for quick help

    As always thank you for your help in advance.

    Riz
    Attached Files Attached Files
    Last edited by rizmomin; 02-04-2013 at 01:26 PM.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Pass Variable in VB Code

    Something like this, perhaps:

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Pass Variable in VB Code

    Hi Andrew:

    Thank you so much for your quick help.
    I need to ask one more favor.
    The name of the closed workbook is not exactly MM_YYYY.xls
    It is in format : MM_YYYY_StoreName.xls.
    I have to do this for numerous store.
    You could set store name variable eg
    STORENAME="DQ_STORE1"
    where i could cahnge STORENAME variable for each store.
    I am sorry, i forgot to mentioned that earlier.
    Can you please incorporate the above file name format so that i can try out the code.

    Thank you

    Riz
    Last edited by rizmomin; 02-04-2013 at 12:21 PM.

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Pass Variable in VB Code

    If you did that then your variable would just go in the name of the workbook to be opened:

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Pass Variable in VB Code

    Hi Andrew:

    Let me try and i will let you know if this would work for me, in few min.

    Thank you so much.

    Riz

  6. #6
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Pass Variable in VB Code

    Hi Andrew:

    Its giving error saying it cannot find File : "01_2013.xls".
    The code should be look for file name : 01_2013_DQFayetteville_DailySales.xls

    Attached is the code i am using.

    Thanks

    Riz
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Pass Variable in VB Code

    This line:

    Please Login or Register  to view this content.
    Needs to be:

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Pass Variable in VB Code

    Hi Andrew:

    You are awesome...this works great.

    Love it and thank you so much for this incredible help.

    Riz

  9. #9
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Pass Variable in VB Code

    Hi Andrew:

    I know i have competed this task with your great help.
    I am writing another VB Macro for another scenerio where i would need to ask "Which Month, year MMMYY" (Example : Jan13)
    Here i have sheet called "Inventory2013" in the same 2031_Yearly.xls file.
    Cell F40:Q40 have heading as Jan13,Feb13,Mar13......Dec13
    Once i have entered which month, Year then need to paste the data under the month (Row 41)

    Here basically, i need the code for destination column.

    Please help me get started this.

    Thanks again

    Riz
    Last edited by rizmomin; 02-04-2013 at 01:35 PM.

  10. #10
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Pass Variable in VB Code

    Hi Andrew:

    I have another post similar kind of requirement...Can you please help me with that since you are familiar with it.
    Thanks

    Title of the new thread is as below.
    "Use value in cell in VB Macro to retrive data and paste"

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Pass Variable in VB Code

    Based on post 8 in this thread, its apparent that you are satisfied with the solution(s) you've received and have solved your question, but you haven't marked your thread as "SOLVED". I will do it for you this time.

    In future, to mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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.6.0 RC 1