Event macro that targets specific worksheet

R

retseort

Hi,

I have this macro and I need it to only target a specific workshee
when it runs. Any help would be appreciated.


Code
-------------------
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.ScreenUpdating = False
BeginRow = 40
EndRow = 70
ChkCol = 9

For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value < 6 Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = True
Else
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
End If
Next RowCnt
Application.ScreenUpdating = True
End Su
 
B

Bob Phillips

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Activesheet.Name = "mySheet" Then
Application.ScreenUpdating = False
BeginRow = 40
EndRow = 70
ChkCol = 9

For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value < 6 Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = True
Else
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
End If
Next RowCnt
Application.ScreenUpdating = True
End If
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
J

Jim May

Say your specific worksheet is (named) MySpecial

After
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.ScreenUpdating = False

"Add" -->> If activesheet.name = "MySpecial" then
Your existing code here...
 
R

retseort

Thanks for the responses. I tried the suggestions and the code does
nothing. Here is the code as per your suggestion.

Basically this code looks at rows 40 thru 70 and hides all rows that
are blank. I want it to run when I save or print.


Code:
--------------------
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "CLIENT_SOW" Then
Application.ScreenUpdating = False
BeginRow = 40
EndRow = 70
ChkCol = 9

For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value < 6 Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = True
Else
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
End If
Next RowCnt
Application.ScreenUpdating = True
End If
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