Worksheet Re-Activate Issue

Ray Rz

New Member
Joined
Jun 19, 2018
Messages
29
I am receiving an error at the Sub Macro2 script for the line of code: "Workbooks.Open Range("N12").
Value where it tells me that it is N12 empty.
How can I reactivate the sheet to pull the file name variable in the file I wrote code in N10, N12, and N14.
N10 works as the sheet is activated.
When it tries for N12, the sheet is no longer activated.
Please let me know if you can assist me on this issue.
Thank youm,
Ray

Code:
[COLOR=#333333]Option Private Module[/COLOR]


[COLOR=#333333]Sub Macro1()[/COLOR]




[COLOR=#333333]MsgBox ("Update may take several minutes, Click Ok to begin")[/COLOR]


[COLOR=#333333]Workbooks.Open Range("N10").Value[/COLOR]

[COLOR=#333333]'Selection.AutoFilter[/COLOR]

[COLOR=#333333]Range("A1:P224").Select[/COLOR]
[COLOR=#333333]Selection.Copy[/COLOR]
[COLOR=#333333]Windows("VBA Extractor r57with code V2.xlsm").Activate[/COLOR]
[COLOR=#333333]Worksheets("Invoice Summary").Activate[/COLOR]
[COLOR=#333333]ActiveCell.Offset(0, 0).Range("A1").Select[/COLOR]
[COLOR=#333333]Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _[/COLOR]
[COLOR=#333333]xlNone, SkipBlanks:=False[/COLOR]


[COLOR=#333333]Call Macro2[/COLOR]


[COLOR=#333333]End Sub[/COLOR]


[COLOR=#333333]Sub Macro2()[/COLOR]


[COLOR=#333333]' Macro2 Macro[/COLOR]
[COLOR=#333333]'[/COLOR]
[COLOR=#333333]' Keyboard Shortcut: Ctrl+f[/COLOR]
[COLOR=#333333]'[/COLOR]
[COLOR=#333333]Workbooks.Open Range("N12").Value[/COLOR]
[COLOR=#333333]'Selection.AutoFilter[/COLOR]
[COLOR=#333333]ActiveCell.Offset(0, 0).Range("A1:AQ35000").Select[/COLOR]
[COLOR=#333333]Selection.Copy[/COLOR]
[COLOR=#333333]Windows("VBA Extractor r57with code V2.xlsm").Activate[/COLOR]
[COLOR=#333333]Worksheets("MyVendor Master").Activate[/COLOR]

[COLOR=#333333]ActiveCell.Offset(-1, 0).Range("A2").Select[/COLOR]
[COLOR=#333333]Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _[/COLOR]
[COLOR=#333333]xlNone, SkipBlanks:=False[/COLOR]




[COLOR=#333333]Call Macro3[/COLOR]


[COLOR=#333333]End Sub[/COLOR]
[COLOR=#333333]Sub Macro3()[/COLOR]




[COLOR=#333333]'[/COLOR]
[COLOR=#333333]' Macro3 Macro[/COLOR]
[COLOR=#333333]'[/COLOR]
[COLOR=#333333]' Keyboard Shortcut: Ctrl+g[/COLOR]
[COLOR=#333333]'[/COLOR]
[COLOR=#333333]Workbooks.Open Range("N14").Value[/COLOR]
[COLOR=#333333]Worksheets("July 2018").Activate[/COLOR]
[COLOR=#333333]Range("A3").Select[/COLOR]
[COLOR=#333333]Selection.AutoFilter[/COLOR]
[COLOR=#333333]Columns("A:E").Select[/COLOR]
[COLOR=#333333]Selection.EntireColumn.Hidden = False[/COLOR]
[COLOR=#333333]Rows("3:3").Select[/COLOR]
[COLOR=#333333]Selection.AutoFilter[/COLOR]
[COLOR=#333333]ActiveCell.Offset(0, 0).Range("A2:BR26000").Select[/COLOR]
[COLOR=#333333]ActiveSheet.Range("$E2").AutoFilter Field:=5, Criteria1:= _[/COLOR]
[COLOR=#333333]"MyVendor"[/COLOR]
[COLOR=#333333]Selection.Copy[/COLOR]
[COLOR=#333333]Windows("VBA Extractor r57with code V2.xlsm").Activate[/COLOR]
[COLOR=#333333]Worksheets("Const. Prog. Rpt Switches").Activate[/COLOR]
[COLOR=#333333]ActiveCell.Offset(0, 0).Range("A1").Select[/COLOR]

[COLOR=#333333]'ActiveCell.Offset(0, 0).Range("A2").Select[/COLOR]

[COLOR=#333333]Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _[/COLOR]
[COLOR=#333333]xlNone, SkipBlanks:=False[/COLOR]


[COLOR=#333333]Call refresh[/COLOR]


[COLOR=#333333]End Sub[/COLOR]






[COLOR=#333333]' Refresh all applicable pivot tables to setup month's data[/COLOR]


[COLOR=#333333]Sub refresh()[/COLOR]
[COLOR=#333333]'[/COLOR]
[COLOR=#333333]' refresh Macro[/COLOR]
[COLOR=#333333]' refresh data[/COLOR]
[COLOR=#333333]'[/COLOR]
[COLOR=#333333]' Keyboard Shortcut: Ctrl+r[/COLOR]




[COLOR=#333333]' replace with Refresh All (had to remove the check for Enable Background refresh to make it wait)[/COLOR]


[COLOR=#333333]ActiveWorkbook.RefreshAll[/COLOR]

[COLOR=#333333]' Refresh all Pivot tables in all worksheets[/COLOR]


[COLOR=#333333]Dim shtTemp As Worksheet[/COLOR]
[COLOR=#333333]Dim pvtTable As PivotTable[/COLOR]

[COLOR=#333333]For Each shtTemp In ActiveWorkbook.Worksheets[/COLOR]
[COLOR=#333333]For Each pvtTable In shtTemp.PivotTables[/COLOR]
[COLOR=#333333]pvtTable.RefreshTable[/COLOR]
[COLOR=#333333]Next[/COLOR]
[COLOR=#333333]Next[/COLOR]
[COLOR=#333333]MsgBox ("Update Complete,All data is Up-to date")[/COLOR]


[COLOR=#333333]End Sub[/COLOR]
 
Last edited by a moderator:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
How about
Code:
Sub Macro1()

[COLOR=#0000ff]Dim ws As Worksheet
Set ws = Sheets("List")
[/COLOR]

MsgBox ("Update may take several minutes, Click Ok to begin")


Workbooks.Open [COLOR=#0000ff]ws.[/COLOR]Range("N10").Value

'Selection.AutoFilter

Range("A1:P224").Select
Selection.Copy
Windows("VBA Extractor r57with code V2.xlsm").Activate
Worksheets("Invoice Summary").Activate
ActiveCell.Offset(0, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False


Call Macro2[COLOR=#0000ff](ws)[/COLOR]


End Sub


Sub Macro2([COLOR=#0000ff]ws As Worksheet[/COLOR])



' Macro2 Macro
'
' Keyboard Shortcut: Ctrl+f
'
Workbooks.Open [COLOR=#0000ff]ws[/COLOR].Range("N12").Value
And do the same sort of thing for macro3
 
Upvote 0
I tried this and I received a <Subscript out of Range> error. I see what I am doing but what do I need the "List" to be to make this work? Is it just the file I want to deem the ws? Let me know if possible.

Thanks for the help.
Ray
 
Upvote 0
You need to change "List" to the name of the sheet that contains the workbook names.
 
Upvote 0
This worked perfectly. Had to set the sheet to my Activate file where I pulled the values from N10, N12, and N14. Thank you very much for your assistance!
Ray
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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