Sorting an Addin Worksheet

G

Guest

Anyone -

Can you tell me the code an Addin would use to sort cells on a worksheet in
the Addin?

I've tried this, but it does not always work:

Workbooks("MyAddInName.xla").Activate
Sheets("Sheet1").Activate
Columns("A:C").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("B1") _
, Order2:=xlAscending, Key3:=Range("C1"), Order3:=xlAscending, Header:= _
xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom


Thank you for any assistance.

MSweetG222
 
D

Dave Peterson

Addins are hidden. And it's not possible to select hidden sheets (or ranges on
sheets that aren't selected).

But you can do it without the .activate and .selects

with Workbooks("MyAddInName.xla").worksheets("Sheet1").range("A:C")
.cells.Sort Key1:=.columns(1), Order1:=xlAscending, _
Key2:=.columns(2), Order2:=xlAscending, _
Key3:=.columns(3), Order3:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
end with
 
G

Guest

Thank you so much.

--
Thx
MSweetG222



Dave Peterson said:
Addins are hidden. And it's not possible to select hidden sheets (or ranges on
sheets that aren't selected).

But you can do it without the .activate and .selects

with Workbooks("MyAddInName.xla").worksheets("Sheet1").range("A:C")
.cells.Sort Key1:=.columns(1), Order1:=xlAscending, _
Key2:=.columns(2), Order2:=xlAscending, _
Key3:=.columns(3), Order3:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
end with
 
G

Guest

Dave - Sorry to bother you again...
I am getting a "Sort method of Range class failed" error.
 
D

Dave Peterson

Did you copy and paste the code or did you type it from scratch?

If you typed it, double check those dots--they're important.

Another thing to check--is the worksheet protected?

If you can't find it, post your code.
 
G

Guest

Thanks for pointing out the dots. Left out the dots on the column keys.
Works perfectly now. Thanks for saving my hair (I was pulling it out)!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top