marcus.brown
Board Regular
- Joined
- Jun 23, 2008
- Messages
- 61
Hi,
I'm trying to create a macro for a colleague, to run an advanced filter on one of their sheets.
I've cobbled together the code below, but if the workbook isn't open, I get an error (Run-time error '9': Subscript out of range). When i click on debug, it highlights the code below which i've put in bold.
Can you please help?
Thanks!
Dim wb As Workbook
Dim AlreadyOpen As Boolean
AlreadyOpen = False
For Each wb In Workbooks
If wb.Name = "Monitor Record Sheet.xlsm" Then
AlreadyOpen = True
Exit For
End If
Next wb
If AlreadyOpen = False Then
Workbooks.Open Filename:="U:\Record Sheet.xlsm", ReadOnly:=True
End If
Workbooks("Record Sheet.xlsm").Sheets("ALL blue monitoring data"). _
Columns("D:AE").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Sheets( _
"Sheet2").Range("A1:A2"), CopyToRange:=Range("A1"), Unique:=False
I'm trying to create a macro for a colleague, to run an advanced filter on one of their sheets.
I've cobbled together the code below, but if the workbook isn't open, I get an error (Run-time error '9': Subscript out of range). When i click on debug, it highlights the code below which i've put in bold.
Can you please help?
Thanks!
Dim wb As Workbook
Dim AlreadyOpen As Boolean
AlreadyOpen = False
For Each wb In Workbooks
If wb.Name = "Monitor Record Sheet.xlsm" Then
AlreadyOpen = True
Exit For
End If
Next wb
If AlreadyOpen = False Then
Workbooks.Open Filename:="U:\Record Sheet.xlsm", ReadOnly:=True
End If
Workbooks("Record Sheet.xlsm").Sheets("ALL blue monitoring data"). _
Columns("D:AE").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Sheets( _
"Sheet2").Range("A1:A2"), CopyToRange:=Range("A1"), Unique:=False