PDA

View Full Version : Why Does Command Button Select and Highlight Whole Page



coliervile
02-26-2008, 07:03 AM
When CommandButton1 is clicked it performs its function, but when it selects worksheet "Dashboard" it actually selects it and highlights the whole page like when you click the top left corner of the worksheet. When CommandButton2 is clicked it does what it's suppose to do, but it actually selects worksheet "Dashboard" without hightlighting the whole page. Is there a reason this is taking place???

Best regards,

Charlie


Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
With frmRequest.ListBox1
'Check for selected item
If (.Value <> vbNullString) Then
Range(.RowSource)(.ListIndex + 1, 1).Value = UserForm4.TextBox1.Value
Range(.RowSource)(.ListIndex + 1, 2).Value = UserForm4.TextBox2.Value
Range(.RowSource)(.ListIndex + 1, 3).Value = UserForm4.TextBox3.Value
Range(.RowSource)(.ListIndex + 1, 4).Value = UserForm4.TextBox4.Value
Range(.RowSource)(.ListIndex + 1, 5).Value = UserForm4.TextBox5.Value

Else
MsgBox "Please Enter Data"

End If
End With
'End With
Unload Me
Cells.Select
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, _
Key1:=Range("B2"), Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Sheets("Dashboard").Select
Application.ScreenUpdating = True
End Sub


Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
Unload Me
Sheets("Dashboard").Select
Application.ScreenUpdating = True
End Sub

MikeO
02-26-2008, 07:41 AM
This is what's selecting the entire sheet:
Cells.Select


If you don't want all of the cells selected after CommandButton1's code is complete, then add this after the sort command:
Range("A1").select

coliervile
02-26-2008, 07:57 AM
Thanks MikeO I'll give it a shot.

Best regards,

Charlie

mdmackillop
02-26-2008, 10:11 AM
No need to select to sort

Cells.Sort Key1:=Range("D2"), Order1:=xlAscending, _
Key1:=Range("B2"), Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom