dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,392
- Office Version
- 365
- 2016
- Platform
- Windows
I have some code that opens a workbook and I then used to code name of the sheet in the opened workbook but it highlights the code name and says variable not defined.
This is the sub I try and run
Could someone help me please?
This is the sub I try and run
VBA Code:
Sub AddYP()
Application.DisplayAlerts = False
Dim newyp As String, wb1 As Workbook
'Assign the name in D5 of the Tracker sheet to the variable newyp
newyp = Tracker.Cells(5, 4)
'Check if List file is open and if not, open it
If Not isFileOpen("List.xlsm") Then
Set wb1 = Workbooks.Open(ThisWorkbook.Path & "\" & "Young People" & "\" & "List.xlsm")
End If
With ActiveWorkbook
'Offset from the bottom of the list of YP by 1 to add the newyp to the list
NamesList.Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = newyp
'Call CreateWB sub and send the variable newyp to it
Call CreateWB(newyp)
'Define a new named range for tblYPNames by resizing the current range by _
one row down
ThisWorkbook.Names.Add Name:="tblYPNames", _
RefersTo:=NamesList.Range("tblYPNames").Resize(NamesList.Range("tblYPNames").Rows.Count + 1)
Tracker.cboYP.ListFillRange = "tblYPNames"
End With
'Sort the YP names list in alphabetical order
Call Sort
Application.DisplayAlerts = True
End Sub
Could someone help me please?