Need help getting macro to run

G

Guest

I have a workbook which currently has 3 sheets. Currently All the
information in entered on a sheet titled <Data Entry>. The information is
then displayed in a Sheet 2. Some or the rows in Sheet 2, don't always have
information in them so I got a macro that will hide those rows, I created a
column <AJ> which either has a constant value in it if I never want it hidden
or it pulls the value from some where in sheet 2 to determine if it is blank
or not. Currently the macro only runs when you click on a cell in sheet 2 or
when you change cells in sheet 2. I would like it to run when ever you print
sheet 2, and when you print preview sheet 2, or if possible to run when ever
information in the <Data Entry> sheet is changed if possible. My code is
entered in the sheet 2 section of VB and looks like this:
<
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Dim cell As Range
Application.ScreenUpdating = False
With ActiveSheet.UsedRange

.Rows.Hidden = False
For Each cell In Range("AJ1:AJ98")
If cell.Value = "" Then _
cell.EntireRow.Hidden = True
Next cell
End With
End Sub
Thanks in advance for your help and advice.
 
O

okrob

I have a workbook which currently has 3 sheets. Currently All the
information in entered on a sheet titled <Data Entry>. The information is
then displayed in a Sheet 2. Some or the rows in Sheet 2, don't always have
information in them so I got a macro that will hide those rows, I created a
column <AJ> which either has a constant value in it if I never want it hidden
or it pulls the value from some where in sheet 2 to determine if it is blank
or not. Currently the macro only runs when you click on a cell in sheet 2 or
when you change cells in sheet 2. I would like it to run when ever you print
sheet 2, and when you print preview sheet 2, or if possible to run when ever
information in the <Data Entry> sheet is changed if possible. My code is
entered in the sheet 2 section of VB and looks like this:
<
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Dim cell As Range
Application.ScreenUpdating = False
With ActiveSheet.UsedRange

.Rows.Hidden = False
For Each cell In Range("AJ1:AJ98")
If cell.Value = "" Then _
cell.EntireRow.Hidden = True
Next cell
End With
End Sub



Thanks in advance for your help and advice.

A good place to start is Chip Pearson's site. He has all kids of
event procedures explained. What it looks like you need to do is put
your macro in a module and call it from several events,
workbook_beforeprint, etc...

http://www.cpearson.com/excel/events.htm

Rob
 

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