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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,717
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,717
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,113
Messages
5,857,454
Members
431,880
Latest member
kar2rost

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
Top