+ Reply to Thread
Results 1 to 8 of 8

Can't get this Macro to work

  1. #1
    Registered User
    Join Date
    06-13-2013
    Location
    Philadelphia PA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Can't get this Macro to work

    Sub Update_Tabs()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
    For Each r In ws.Range("B1:L1")
    If r.Value = "No" Then
    r.EntireColumn.Hidden = True
    Else
    r.EntireColumn.Hidden = False
    End If
    Next ws
    End Sub

    I am just trying to hide any column that says No in it's first cell on each sheet. I got it to work on just one sheet, but I am messing something up when I tried to add in the apply to all tabs part.

    Anybody know what I'm doing wrong?

    Thanks in advance

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Can't get this Macro to work

    Hi tyler,

    If you indent your code you would have found that you didn't provide a Next r.
    Please Login or Register  to view this content.
    Also, and just to go one step further, you can declare r too, much like how you nicely declared ws
    Please Login or Register  to view this content.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    06-13-2013
    Location
    Philadelphia PA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Can't get this Macro to work

    Ahhh you just made my day, thank you!

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Can't get this Macro to work

    tyler, Im happy that you had your question resolved

    For future reference, please ensure that your thread title complies with Forum Rule #1 about proper thread titles.

    Thanks
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Can't get this Macro to work

    And of course,
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Can't get this Macro to work

    lol thanks Mordred, I missed that

  7. #7
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Can't get this Macro to work

    I missed it all originally.

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Can't get this Macro to work

    I guess I read the title, opened it and skipped to the bottom - saw that the question was answered and didnt look further

+ 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. [SOLVED] Macro Doesn't Work Through Button, Does Work Through Developer ->Macros Option
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-27-2013, 11:55 AM
  2. [SOLVED] How to make the macro work for all rows in the work sheet
    By Valli nayaki in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2013, 10:43 PM
  3. MAcro does not work when certain cells in a work sheet are protected
    By Unnati in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2012, 03:38 AM
  4. Macro to collate data from different work books and different work sheets
    By bvdileep in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2012, 05:34 AM
  5. Replies: 2
    Last Post: 07-11-2006, 11:15 PM

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