+ Reply to Thread
Results 1 to 12 of 12

Macro that reads worksheets

  1. #1
    Forum Contributor
    Join Date
    03-09-2010
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2003
    Posts
    173

    Macro that reads worksheets

    Hello!

    I have a workbook, with several worksheets. The worksheets are named iex
    Test 1
    Test 2
    Test 3

    What I want to do is having the makro understand that if a new worksheet is generated, for example "Test 4", then this dimmed as the new variable which I use in reference in the following coding.

    Is it possible?
    Last edited by Hjahren; 09-28-2010 at 09:39 AM.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro that reads worksheets

    If the new sheet will always be the last one to the right on you tabs you can use:

    Please Login or Register  to view this content.

    You would need to control how tabs are added to the workbook and protect the workbook structure. Another approach might be to loop through each worksheet and work out which one has the highest number.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,528

    Re: Macro that reads worksheets

    What following coding?

  4. #4
    Forum Contributor
    Join Date
    03-09-2010
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2003
    Posts
    173

    Re: Macro that reads worksheets

    I have a macro which will use the sheet with the highest number, but there are also other worksheets that doesn't start with test.

    The ideal would be that the macro selected or dimmed the worksheet with "Test ##" and the highest number.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,257

    Re: Macro that reads worksheets

    Something like:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  6. #6
    Forum Contributor
    Join Date
    03-09-2010
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2003
    Posts
    173

    Re: Macro that reads worksheets

    I got:

    "Compile error:

    Dupiclate declaration in current scope".

    And it was when running the first line "wks as worksheet"

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,257

    Re: Macro that reads worksheets

    Then remove that part. You didn't post much code so I assumed you hadn't declared anything.

  8. #8
    Forum Contributor
    Join Date
    03-09-2010
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2003
    Posts
    173

    Re: Macro that reads worksheets

    wks doesnt get a value, but the macro runs through the function you gave without a problem. I get "type mismatch" error at sheets(wks).Select

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,257

    Re: Macro that reads worksheets

    Where in my code does it say:
    Please Login or Register  to view this content.
    ?

  10. #10
    Forum Contributor
    Join Date
    03-09-2010
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2003
    Posts
    173

    Re: Macro that reads worksheets

    Please Login or Register  to view this content.
    I believed that this sentence dimmed wks as the spreadsheet

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,257

    Re: Macro that reads worksheets

    That's not what I'm asking. My code says:
    Please Login or Register  to view this content.
    not
    Please Login or Register  to view this content.
    because wks is a worksheet, not the name of one.

  12. #12
    Forum Contributor
    Join Date
    03-09-2010
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2003
    Posts
    173

    Re: Macro that reads worksheets

    Stupid me

+ 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