Hiding complete Rows using a procedure

G

Guest

I want to hide rows 5,6 and 7 in a worksheet, I recorded the following macro
but it hides all rows containing data from 5 downwards.

Sub HideSetupRows()
Rows("5:7").Select
Range("B5").Activate
Selection.EntireRow.Hidden = True
Range("B8").Select
End Sub

I have no idea why this happens, could any one offer an expaination?

Thanks in advance

Mark
 
P

PCLIVE

I would suspect you have some other code running to cause this. The code
you've posted works fine for me.
 
G

Guest

Mark -

Your procedure looks fine and works properly when I test it, although it
does have some unnecessary statements (see alternative below). Consider the
fact that all of your statements operate on the activesheet (whatever sheet
you see when you invoke the macro). Are you viewing a different sheet after
running the macro ? This would give the illusion of failure.

Try running the macro while viewing the worksheet instead of from the VB
Editor. Press Alt+F8, select your macro, and choose Run. Let us know what
happens.

Alternative:
Sub HideSetupRows()
Rows("5:7").Hidden = True
End Sub
 
G

Guest

This is a bit wierd

I was calling this sub from an option button on a multipage user form, to
see what was happening I changed the code to

Rows ("5:7").Select

and placed it in the OptionButton_Click sub directly instead of caling it
and for some bizarre reason rows 2:59 are being selected

I do have a couple of ontime procedures running and the active sheet has a
Worksheet_change routine but i can't see how they would matter
 
G

Guest

I've moved the row statements into 2 subs in a standard module and called
them from the option buttons in thee user form and all is ok now.

Thanks for your help guys

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top