Trying to pass sheet name to variable - results pass sheet number instead

  • I wrote some script that runs through worksheets named 1 through 31 and copies a set range from each worksheet to the next available cell on a worksheet named "Camp Track Sheet". Instead of the code recognizing the sheet name it pulls data from the sheet numbers so I am getting some wrong data pulled into the "Camp Track Sheet: worksheet.


    The code is as follows:




    What am I missing?


    Many Thanks!


    Ray

  • Re: Trying to pass sheet name to variable - results pass sheet number instead


    Hi Ray,


    Not sure what's wrong with your code but see how this goes:



    Note individual tabs like this (I take it they're for each day of any month) are rarely the way to go. It's usually much better to have one tab for all the data with an extra column for the day number or date from which all your reporting can run off (in my humble opinion).


    HTH


    Robert

  • Re: Trying to pass sheet name to variable - results pass sheet number instead


    Thanks for your response Robert.


    With the spreadsheet there are other worksheets within the file. Worksheets named "1" through "31" hold the financial data that I want to copy and paste to the "Camp Track Sheet". Reading your code, it looks like it loops though all the worksheets with the exception of the "Camp Track Sheet". As well, I want the financial data to copy and paste in chronological order.

  • Re: Trying to pass sheet name to variable - results pass sheet number instead


    Instead of Sheets(sheetn) use sheets(Cstr(sheetn))

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!