Recording Macros

J

JMS

I am using Excel 2003, with Windows XP Professional.

I have no prior knowledge of macros, so this may be a beginner problem.

I have a worksheet where I have dozens of groups of repeating rows.
I wanted to hide the same rows (non-contiguous rows) in every group.
So I recorded a macro, whereby I selected the non-contiguous rows for one of
the groups, then hid the rows.

Here is the VBA language from the recorded macro:


Range("187:187,189:189,192:192,199:199,200:200,202:202,204:204,206:206,208:208" _
).Select
Range("A208").Activate
Selection.EntireRow.Hidden = True
End Sub

When I go to run this macro further down the same spreadsheet, it does not
do anything. I assumed, I could run it at any particular spot in the
spreadsheet, and it would hide the relative rows from my new starting point.

Any help would be appreciated.

Thanks,
Jamie
 
M

Michael Arch

Per your macro, the numbers you see are those rows (And only those rows) that
will be hidden when your macro runs. In order to hide other rows you must
have an identifying criteria, and base your row hidding macro on that
criteria. Alternatively, you may want to use the Autofilter Method: Click on
the column where your filtering criteria is and From the main menu select
Data->Autofilter.
From the Dropdown box you can select custom and select criteria based on
predefined Excel functionality.
 
J

Joel

The rows are fixed in the macro base on the numbers row 187, 189,192....

How can you tell when one group ends and the next group starts? I can write
a mcro that will run down the worksheet baed on the start and end of each
group.
 
B

Bob Phillips

See if this helps

Public Sub Test()

Call HodeRows(187)
'etc.
End Sub

Sub HideRows(StartRow As Long)
Union(Rows(StartRow), Rows(StartRow + 2), Rows(StartRow + 5), _
Rows(StartRow + 12), Rows(StartRow + 13), Rows(StartRow + 15), _
Rows(StartRow + 17), Rows(StartRow + 19), Rows(StartRow +
21)).Hidden = True
End Sub
 

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