Consulting

Results 1 to 4 of 4

Thread: (Un)Hide columns based on a list

  1. #1
    VBAX Tutor
    Joined
    Mar 2010
    Posts
    287
    Location

    (Un)Hide columns based on a list

    Hi all...

    I have a named range in Worksheets("INDEX").Range("EMAILCOLS") that contains details of columns to be hidden before I email the sheet

    The sheet containing the data ("POSITIONS") has a range defined called 'filteredrange'

    I wanted to do a function to check each cell in row 1, and if Find is not nothing for "EMAILCOLS" then hide the entire column

    Then reverse it after the email send. I cannot get it to work though

    Would like it to be simple e.g.

    r1 = Worksheets("POSITIONS").Range("filteredrange")
    r2 = Worksgeets("INDEX").Range("EMAILCOLS")

    ColumnVisible(r1,r2,0) <--- Use 0 = False to hide the columns
    ColumnVisible(r1,r2,0) <--- Use 1 = True to show the columns

    For the logic I was considering

    For each rng in r2 - check if Find gives a result in r1.Rows(1) and if it does then entirecolumn.hidden = true but I can't get it right

    Any help appreciated

    Kind regards

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Set r1 = Worksheets("POSITIONS").Range("filteredrange")
    Set r2 = Worksgeets("INDEX").Range("EMAILCOLS")

    For Each rng In r2

    rng.EntireColumn.Hidden = Not IsError(Application.Match(rng.Value, r1, 0))
    Next rng
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Mar 2010
    Posts
    287
    Location

    Question

    How would I achieve this using Find - it runs very slow with match

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Have you turned off Screenupdating and set calculation mode to manual?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •