Consulting

Results 1 to 4 of 4

Thread: Hide Rows based on variable

  1. #1

    Hide Rows based on variable

    I'm trying to hide rows in excel based on a VBA variable. The variable in my program is Days. Can someone help me make this work. This is what I tried...

    Public Days As Single
    Rows(Days:368).Select
    Selection.EntireRow.Hidden = True


    I'm confident Days is working as a variable, because I tested it with:
    MsgBox Days

    Thank you,
    Kaela

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Kaela

    Days may be 'working' as a variable but you aren't using it correctly.

    Try this, untested, code.
    [vba]
    Public Days As Single
    Rows(Days & ":368").EntireRow.Hidden = True
    [/vba]
    PS Where are you actually giving Days a value?

  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Kaela,

    Can you post your code in its entirety and explain what it is that you are trying to accomplish?

    [uvba]a[/uvba]

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Best to make it a Long variable, and EntireRow is redundant

    [vba]

    Public Days As Long


    Rows(Days & ":368").Hidden = True

    [/vba]

Posting Permissions

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