ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Run time error 1004 - what have I done wrong? (https://www.excelbanter.com/excel-discussion-misc-queries/101269-run-time-error-1004-what-have-i-done-wrong.html)

alexwren

Run time error 1004 - what have I done wrong?
 

Anybody know why this is a problem?


Code:
--------------------
Sheets("data").Select
h = UsedRange.Rows.Count
Rows("2:" & h).Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("H2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
--------------------


Alex


--
alexwren
------------------------------------------------------------------------
alexwren's Profile: http://www.excelforum.com/member.php...o&userid=36767
View this thread: http://www.excelforum.com/showthread...hreadid=564910


Chip Pearson

Run time error 1004 - what have I done wrong?
 
You need to change
h = UsedRange.Rows.Count
to
h = ActiveSheet.UsedRange.Rows.Count



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"alexwren"
wrote in
message
...

Anybody know why this is a problem?


Code:
--------------------
Sheets("data").Select
h = UsedRange.Rows.Count
Rows("2:" & h).Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,
Key2:=Range("H2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1,
MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
--------------------


Alex


--
alexwren
------------------------------------------------------------------------
alexwren's Profile:
http://www.excelforum.com/member.php...o&userid=36767
View this thread:
http://www.excelforum.com/showthread...hreadid=564910





All times are GMT +1. The time now is 08:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com