larinda4
Board Regular
- Joined
- Nov 15, 2021
- Messages
- 73
- Office Version
- 365
- Platform
- Windows
I'll describe what I need it to do first and maybe that will help figuring it out.
On a separate tab (we'll call it List) it contains a list of numbers in column A and the location it should be saved (PDF'd) in column E.
I want it to pull the first number from column A into another tab called Master that already has formulas that will generate information that I need. However, I want to hide rows that are not applicable to this specific number before it PDF's it to the location from Column E in the List tab.
I'll need it to hide rows based on a value of 1 (again, I used formulas in the Master tab) and then unhide the rows after it PDF's it. Grab the next number from the List tab, hide applicable rows, PDF it, then unhide the rows, rinse and repeat.
Here's my code:
Sub PrintbyDiv()
I = 189
Do While I < 197
Sheets("List").Select
Cells(I, 1).Select
Selection.Copy
Sheets("Master").Select
Range("B8").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Dim wbBook As Workbook
Dim wsSheet As Worksheet
If wbBook.Worksheets("Master").Range("P69").Value = 1 Then
wbBook.Worksheets("Master").Rows("68:70").EntireRow.Hidden = True
End If
If wbBook.Worksheets("Master").Range("P72").Value = 1 Then
wbBook.Worksheets("Master").Rows("71:73").EntireRow.Hidden = True
End If
If wbBook.Worksheets("Master").Range("P72").Value = 1 Then
wbBook.Worksheets("Master").Rows("71:73").EntireRow.Hidden = True
End If
If wbBook.Worksheets("Master").Range("P75").Value = 1 Then
wbBook.Worksheets("Master").Rows("74:76").EntireRow.Hidden = True
End If
If wbBook.Worksheets("Master").Range("P77").Value = 1 Then
wbBook.Worksheets("Master").Rows("77:80").EntireRow.Hidden = True
End If
If wbBook.Worksheets("Master").Range("P81").Value = 1 Then
wbBook.Worksheets("Master").Rows("81:83").EntireRow.Hidden = True
End If
If wbBook.Worksheets("Master").Range("P84").Value = 1 Then
wbBook.Worksheets("Master").Rows("84:86").EntireRow.Hidden = True
End If
Sheets("PrintQ").Select
ThisFile = Cells(I, 5).Value
Sheets("Master").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisFile, Quality:=xlQualityStandard, _
IgnorePrintAreas:=False, OpenAfterPublish:= _
False
I = I + 1
Loop
End Sub
The DEBUG prompt happens as soon as it hits my first if statement to hide rows. It says "Run-time Error '91': Object variable or With block variable not set". What am I doing wrong?
On a separate tab (we'll call it List) it contains a list of numbers in column A and the location it should be saved (PDF'd) in column E.
I want it to pull the first number from column A into another tab called Master that already has formulas that will generate information that I need. However, I want to hide rows that are not applicable to this specific number before it PDF's it to the location from Column E in the List tab.
I'll need it to hide rows based on a value of 1 (again, I used formulas in the Master tab) and then unhide the rows after it PDF's it. Grab the next number from the List tab, hide applicable rows, PDF it, then unhide the rows, rinse and repeat.
Here's my code:
Sub PrintbyDiv()
I = 189
Do While I < 197
Sheets("List").Select
Cells(I, 1).Select
Selection.Copy
Sheets("Master").Select
Range("B8").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Dim wbBook As Workbook
Dim wsSheet As Worksheet
If wbBook.Worksheets("Master").Range("P69").Value = 1 Then
wbBook.Worksheets("Master").Rows("68:70").EntireRow.Hidden = True
End If
If wbBook.Worksheets("Master").Range("P72").Value = 1 Then
wbBook.Worksheets("Master").Rows("71:73").EntireRow.Hidden = True
End If
If wbBook.Worksheets("Master").Range("P72").Value = 1 Then
wbBook.Worksheets("Master").Rows("71:73").EntireRow.Hidden = True
End If
If wbBook.Worksheets("Master").Range("P75").Value = 1 Then
wbBook.Worksheets("Master").Rows("74:76").EntireRow.Hidden = True
End If
If wbBook.Worksheets("Master").Range("P77").Value = 1 Then
wbBook.Worksheets("Master").Rows("77:80").EntireRow.Hidden = True
End If
If wbBook.Worksheets("Master").Range("P81").Value = 1 Then
wbBook.Worksheets("Master").Rows("81:83").EntireRow.Hidden = True
End If
If wbBook.Worksheets("Master").Range("P84").Value = 1 Then
wbBook.Worksheets("Master").Rows("84:86").EntireRow.Hidden = True
End If
Sheets("PrintQ").Select
ThisFile = Cells(I, 5).Value
Sheets("Master").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisFile, Quality:=xlQualityStandard, _
IgnorePrintAreas:=False, OpenAfterPublish:= _
False
I = I + 1
Loop
End Sub
The DEBUG prompt happens as soon as it hits my first if statement to hide rows. It says "Run-time Error '91': Object variable or With block variable not set". What am I doing wrong?