+ Reply to Thread
Results 1 to 7 of 7

My macro runs on hidden sheets (and it shouldn't)

  1. #1
    Registered User
    Join Date
    02-09-2015
    Location
    Paris
    MS-Off Ver
    Office 2013
    Posts
    5

    My macro runs on hidden sheets (and it shouldn't)

    Hi!

    I am super-beginner in the macro world. We have a macro that reads certain columns and rows in all sheets of different excel files, and then writes them in a new excel file. My problem is that it even considers the hidden sheets and I don't know why. This creates me problems to organize information in pivot tables. Could you help me?

    I = 1
    For Each objFile In objFolder.Files
    Workbooks.Open (objFile)

    For csht = 1 To ActiveWorkbook.Sheets.Count 'worksheet or sheets
    With ActiveSheet
    lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
    For teller = 11 To lastRow
    'print no of worksheets
    Cells(I + 1, 3) = ActiveWorkbook.Worksheets.Count
    'print sheetname
    Cells(I + 1, 4) = Sheets(csht).Name
    Range(Cells(I + 1, 5), Cells(I + 1, 25)) = Sheets(Sheets(csht).Name).Range("A" & teller & ":Z" & teller).Value
    I = I + 1
    Next teller
    Next csht



    Thank you!

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: My macro runs on hidden sheets (and it shouldn't)

    nagonar,

    A few things... please don't post duplicate threads. Also, always surround your code in code tags. Highlight code, and hit the # symbol in the menu.

    see if this code works for you....

    Please Login or Register  to view this content.
    Last edited by Arkadi; 02-09-2015 at 11:24 AM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: My macro runs on hidden sheets (and it shouldn't)

    To omit hidden sheets you need to tell the code to do such. Also, make sure your sheet references are what you want. Each range should have a proper sheet reference in your scenario.

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    05-30-2013
    Location
    France
    MS-Off Ver
    2010
    Posts
    260

    Re: My macro runs on hidden sheets (and it shouldn't)

    You can work with the Visible property.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-09-2015
    Location
    Paris
    MS-Off Ver
    Office 2013
    Posts
    5

    Re: My macro runs on hidden sheets (and it shouldn't)

    First of all sorry Arkadi for the multiple post. I will take your recommendations into account for the future posts.

    And thanks Stnkynts and Amphinomos for your fast answers, ActiveSheet.Visible feature worked! Ha! happy girl.

    Cheers.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: My macro runs on hidden sheets (and it shouldn't)

    No problem

    Amphinomos and I seem to have thought of the same code solution, but careful... "next teller" in his code is outside the if statement, while the start of the for loop is inside. That could cause errors. I suggest moving "end if" to just after "next teller" instead of just before. Cheers

  7. #7
    Registered User
    Join Date
    02-09-2015
    Location
    Paris
    MS-Off Ver
    Office 2013
    Posts
    5

    Re: My macro runs on hidden sheets (and it shouldn't)

    Yes, that is what Stnkynts suggested and what I did, otherwise it was giving me a compile error.

    Thanks, have a good day.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Viewing Hidden Sheets with a macro
    By Shazz in forum Excel General
    Replies: 9
    Last Post: 03-13-2012, 02:22 PM
  2. Macro to find hidden sheets
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-14-2011, 02:26 PM
  3. Macro to print on sheets which are not hidden
    By BRISBANEBOB in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-23-2008, 04:40 AM
  4. this macro runs, but not with a filter on the sheets?
    By matthias in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-11-2006, 04:45 PM
  5. [SOLVED] Macro and hidden sheets
    By Metallo in forum Excel General
    Replies: 7
    Last Post: 01-19-2006, 05:35 AM

Tags for this Thread

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