Filename.XLSM works but not Personal.xlsb

Zab Trader

New Member
Joined
Feb 19, 2019
Messages
5
This is beginning part of a macro that worked fine in a xlsm file.
To share the code saved it as a Personal Macro.
Problem is it fails at the 3rd line. Line1 worked fine, so sheet is there.
Run-time Error 9 subscript out of range error
Code:
 ActiveSheet.Name = "Not Quoted"
Dim wsSummary As Worksheet
Set wsSummary = ThisWorkbook.Sheets("Not Quoted")
Dim NewWB As Workbook
    ChDrive "C:"
    NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsx), *.xlsx", Title:="Select Data File That Supplier Provided")
        If NewFN = False Then
        MsgBox "Exiting Program For No File Selected"
        Exit Sub
    Else
    Set NewWB = Workbooks.Open(Filename:=NewFN, ReadOnly:=True)
    End If
Dim wsData As Worksheet
Set wsData = NewWB.Sheets("Sheet1")
    LastRow1 = NewWB.Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
    wsSummary.Range("A3:A3" & LastRow1).Value = wsData.Range("F3:F3" & LastRow1).Value
    wsSummary.Range("B3:B3" & LastRow1).Value = wsData.Range("D3:D3" & LastRow1).Value
    NewWB.Close
Thanks, Zab
 

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,110
Office Version
  1. 365
Platform
  1. Windows
Its because ThisWorkbook is the workbook which houses the code so in your case Personal.xlsb. The sheet wont be in Personal.xlsb.
 

Zab Trader

New Member
Joined
Feb 19, 2019
Messages
5
That makes sense, what would the solution look like. Instead of (this) change it to open?
Thanks
 

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,110
Office Version
  1. 365
Platform
  1. Windows
Maybe ActiveWorkbook be better. That is then obviously the workbook that is active at the time the line of code executes.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,030
Messages
5,526,344
Members
409,697
Latest member
christopherlewis1620

This Week's Hot Topics

Top