From: Phyllis on
I am wanting to sort data in a worksheet from a command button on a different
worksheet. I want the focus to stay (or at least return) to the worksheet
containing the command button. Is this even possible? If so, could someone
supply a sample of code? Both worksheets are in the same workbook. Using
excel 2003 .
From: Dave Peterson on
Yes. The trick is to not select the other sheet.

Option Explicit
Private Sub CommandButton1_Click()

Dim wks As Worksheet
Dim myRng As Range

Set wks = Me.Parent.Worksheets("Sheet2") 'some other sheet

With wks
Set myRng = .Range("A1:x99") 'some range
End With

With myRng
.Cells.Sort _
key1:=.Columns(1), order1:=xlAscending, _
key2:=.Columns(3), order1:=xlAscending, _
header:=xlYes
End With
End Sub

Phyllis wrote:
>
> I am wanting to sort data in a worksheet from a command button on a different
> worksheet. I want the focus to stay (or at least return) to the worksheet
> containing the command button. Is this even possible? If so, could someone
> supply a sample of code? Both worksheets are in the same workbook. Using
> excel 2003 .

--

Dave Peterson
From: Dave Peterson on
Check your other post.

Phyllis wrote:
>
> I am wanting to sort data in a worksheet from a command button on a different
> worksheet. I want the focus to stay (or at least return) to the worksheet
> containing the command button. Is this even possible? If so, could someone
> supply a sample of code? Both worksheets are in the same workbook. Using
> excel 2003 .

--

Dave Peterson
From: Dave Peterson on
Oops. I must have been seeing double!

Dave Peterson wrote:
>
> Check your other post.
>
> Phyllis wrote:
> >
> > I am wanting to sort data in a worksheet from a command button on a different
> > worksheet. I want the focus to stay (or at least return) to the worksheet
> > containing the command button. Is this even possible? If so, could someone
> > supply a sample of code? Both worksheets are in the same workbook. Using
> > excel 2003 .
>
> --
>
> Dave Peterson

--

Dave Peterson
 | 
Pages: 1
Prev: disable pageup and pagedown
Next: Macro buttons