dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,392
- Office Version
- 365
- 2016
- Platform
- Windows
I have a spreadsheet that works fine but I have just been told the combo box that pulls a named range from another sheet needs to sort in alphabetical order.
I run this procedure to add a young person
It works fine until it gets down to the sort sub
I get the error method range of object worksheet failed with this line highlighted
The combo box has a listfillrange of tblYPNames.
Can someone help me please?
I run this procedure to add a young person
VBA Code:
Sub AddYP()
Application.DisplayAlerts = False
Dim newyp As String
'Assign the name in D5 of the Tracker sheet to the variable newyp
newyp = Tracker.Cells(5, 4)
'Offset from the bottom of the list of YP by 1 to add the newyp to the list
YP.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:=Range("tblYPNames").Resize(Range("tblYPNames").Rows.Count + 1)
Tracker.cboYP.ListFillRange = "tblYPNames"
'Sort the YP names list in alphabetical order
Call Sort
Application.DisplayAlerts = True
End Sub
It works fine until it gets down to the sort sub
I get the error method range of object worksheet failed with this line highlighted
VBA Code:
Sub Sort()
YP.Range("A2", Range("A2").End(xlUp)).Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlNo
End Sub
The combo box has a listfillrange of tblYPNames.
Can someone help me please?