Worksheet reference issue?

Ray Rz

New Member
Joined
Jun 19, 2018
Messages
29
I have a macro that should run but I am linking it to cell N14 for the file name and cell N16 for the Worksheet tab name.
I cannot get this macro to run and it stops where I reference the worksheet name in cell N16.
If someone could look at this and possibly assist me, I would appreciate it.

Thank you,
Ray
------------------------------------------------

Code:
Sub Macro3(ws As Worksheet)




'
' Macro3 Macro
'
' Keyboard Shortcut: Ctrl+g
'


Workbooks.Open ws.Range("N14").Value
Worksheets wks.Range("N16").Activate
'
'
Dim wks As Excel.Worksheet


On Error Resume Next
    Set wks = ThisWorkbook.Worksheets(Sheets("Start").Range("N16").Value)
On Error GoTo 0


If Not wks Is Nothing Then
    Call wks.Activate
    
        'Worksheets("July 2018").Activate where the value of cell N16 is July 2018
        Range("A3").Select
    Selection.AutoFilter
    Columns("A:E").Select
    Selection.EntireColumn.Hidden = False
    Rows("3:3").Select
    Selection.AutoFilter
    ActiveCell.Offset(0, 0).Range("A2:BR26000").Select
        ActiveSheet.Range("$E2").AutoFilter Field:=5, Criteria1:= _
        "Haugland"
    Selection.Copy
    Windows("VBA Extractor r57with code V2.xlsm").Activate
    Worksheets("Const. Prog. Rpt Switches").Activate
    ActiveCell.Offset(0, 0).Range("A1").Select
    
    'ActiveCell.Offset(0, 0).Range("A2").Select
    
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False


Call refresh


'    End If


End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Maybe
Code:
Worksheets(ws.Range("N16")).Activate
 
Upvote 0
Try,

Dim WorksheetName As String: WorksheetName = Cells(14, 14)
Dim PageName As String: PageName = Cells(16, 14)
 
Upvote 0
Fluff,
I tried this activate and it did not work as intended. I have the code that works with my month hard coded in the tab name. If I were to send you the code that worked, would you be able to look at it? Please let me know.

Thanks,
Ray
 
Upvote 0
Code failed. Did not continue. Aborted procedure with no selection because tab was not able to be located.
 
Upvote 0
You are passing a variable to the code (ws) is that the sheet that contains the N16 value?
Also what is the value in N16?
 
Upvote 0
The value of cell N16 on the tab named Start is "July 2018" without the quotes. The ws passed for the variable. Do I need to pass another variable for this to work? I am unsure. Please let me know if you can help.

Thanks,
Ray
 
Upvote 0
What is the name of the sheet ws that you are passing to the macro?
 
Upvote 0
The name of the ws sheet is Start.
Essentially, Start!N10, Start!N12, Start!N14, and Start!N16 are being called. The Start!16 references a tab and that is what is messing me up.
Ray
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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