I'm using this to sort a worksheet from a User Form:
However if sheet1 is not active I get a run time error.
What am I doing wrong ?
Code:
Private Sub UserForm_Initialize()
With Sheet1
.Cells.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Me.lbxCustomers.List = .Range(.[A2], .Cells(Rows.Count, 1).End(xlUp)).Value
End With
End Sub
However if sheet1 is not active I get a run time error.
What am I doing wrong ?