ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need help getting macro to run (https://www.excelbanter.com/excel-programming/388759-need-help-getting-macro-run.html)

Kiba

Need help getting macro to run
 
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.

okrob

Need help getting macro to run
 
On May 4, 10:19 am, Kiba wrote:
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


Kiba

Need help getting macro to run
 
Thanks,

That site was a lot of help.

"okrob" wrote:

On May 4, 10:19 am, Kiba wrote:
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




All times are GMT +1. The time now is 02:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com