PDA

View Full Version : hide every n-th row



lior03
11-18-2007, 11:55 PM
hello
i am trying to hide/unhide every 3 row between rows 2 to 20.

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

Bob Phillips
11-19-2007, 12:54 AM
Dim i As Integer
For i = 1 To 20 Step 3
Rows(i).Visible = Not Rows(i).Visible
Next i

lior03
11-19-2007, 01:10 AM
it failed in my excel

lior03
11-19-2007, 01:13 AM
sorry
what about:

On Error Resume Next
Dim i As Integer
For i = 2 To 15 Step 2
Rows(i).Hidden = Not Rows(i).Hidden
Next i

Bob Phillips
11-19-2007, 01:37 AM
That will teach me to test it



Dim i As Integer
For i = 1 To 20 Step 3
Rows(i).Hidden = Not Rows(i).Hidden
Next i

lior03
11-19-2007, 02:52 AM
hello
this is a general version.is there any thing you can suggest to improve it?

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


can i symplfy the variable definition & the inputbox?
thanks

Bob Phillips
11-19-2007, 03:01 AM
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.

lior03
11-19-2007, 03:39 AM
so can you suggest alternative neat approach for writting this code?

Bob Phillips
11-19-2007, 03:41 AM
I think the gist of my answer is that there is nothing there to get one's teeth into, so no I can't.