Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting Worsheet from a User form 1

Status
Not open for further replies.

johnny45

Technical User
Nov 8, 2006
136
CA
I'm using this to sort a worksheet from a User Form:
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 ?
 




Refernce ALL ranges to Sheet1...
Code:
   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

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top