Excel Macro Stopped Working - Worksheets (i).Select ReplaceFlag

MarkB5432

New Member
Joined
Jul 3, 2020
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi,

The following macro has stopped working and I have no idea why? The debug is stopping on the line with the red text below... "Worksheets (i).Select ReplaceFlag"

(I'm running MSOffice 12624.20588)

Please would somebody be able to assist?

Thanks!

Mark



1605611851914.png



Sub Collapse_Columns_Save_PDF()

'Macro collapses Columns and Rows between the START and END tabs, then saves as PDF

Dim currentSheet As Worksheet
Dim replaceFlag As Boolean
Dim i As Long
With ThisWorkbook
replaceFlag = True
Set currentSheet = .ActiveSheet

'Step 1 - Collapse all Columns & Rows between the START & END tabs

For i = .Worksheets("Start -->").Index + 1 To .Worksheets("<-- End").Index - 1
.Worksheets(i).Outline.ShowLevels RowLevels:=1, ColumnLevels:=1
.Worksheets(i).Select replaceFlag
replaceFlag = False

'Step 2 - Save all tabs between START & END tabs as a pdf document

Next
.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Replace(.FullName, ".xlsb", ".pdf"), _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
currentSheet.Select
End With

End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Any hidden sheets in the workbook?
 
Upvote 0
For reference, there are about 45 worksheets in between the range 'Start -->' and '<--- End'
 
Upvote 0

Forum statistics

Threads
1,215,743
Messages
6,126,609
Members
449,321
Latest member
syzer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top