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
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Its because ThisWorkbook is the workbook which houses the code so in your case Personal.xlsb. The sheet wont be in Personal.xlsb.
 
Upvote 0
Maybe ActiveWorkbook be better. That is then obviously the workbook that is active at the time the line of code executes.
 
Upvote 0

Forum statistics

Threads
1,214,881
Messages
6,122,074
Members
449,064
Latest member
MattDRT

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