Consulting

Results 1 to 9 of 9

Thread: hide every n-th row

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    hide every n-th row

    hello
    i am trying to hide/unhide every 3 row between rows 2 to 20.
    [VBA]
    Dim i As Integer
    For i = 1 To 20 Step 3
    If Rows(i).ishidden = True Then
    Rows(i).ishidden = False
    else
    rows(i).ishidden=true
    End If
    Next i

    [/VBA]
    moshe

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

    Dim i As Integer
    For i = 1 To 20 Step 3
    Rows(i).Visible = Not Rows(i).Visible
    Next i
    [/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 Mentor
    Joined
    Jun 2005
    Posts
    374
    Location
    it failed in my excel
    moshe

  4. #4
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location
    sorry
    what about:
    [VBA]
    On Error Resume Next
    Dim i As Integer
    For i = 2 To 15 Step 2
    Rows(i).Hidden = Not Rows(i).Hidden
    Next i

    [/VBA]
    moshe

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That will teach me to test it

    [vba]

    Dim i As Integer
    For i = 1 To 20 Step 3
    Rows(i).Hidden = Not Rows(i).Hidden
    Next i
    [/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

  6. #6
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location
    hello
    this is a general version.is there any thing you can suggest to improve it?
    [VBA]
    On Error Resume Next
    Dim i As Integer
    Dim sts As Integer
    Dim enr As Integer
    Dim itr As Integer
    sts = Application.InputBox("start row", "begin where", , , , , , 2)
    enr = Application.InputBox("end where", "stop", , , , , , 2)
    itr = Application.InputBox("each of everyrow?", "interval", , , , , , 2)
    For i = 2 To 15 Step 2
    Rows(i).Hidden = Not Rows(i).Hidden
    Next i

    [/VBA]
    can i symplfy the variable definition & the inputbox?
    thanks
    moshe

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It is a bit short to look for improvements, but you do declare variables and set them up but do not use them (more code that we don't see?).

    Also, you declare Integer variables, it is better to use Long than Integer.
    ____________________________________________
    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

  8. #8
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location
    so can you suggest alternative neat approach for writting this code?
    moshe

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I think the gist of my answer is that there is nothing there to get one's teeth into, so no I can't.
    ____________________________________________
    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
  •