Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default runtime 1004 error

Here is the whole macro. There is a type mismatch on the first set range
presumably because it is not a range type variable. But if I change the
range variant type to range it does the same thing.
Thanks,


Public Sub CoerceAsNumDeptIDSort()

Dim Rng, rng1 As Range
Dim cell As Range
'finds the number of the last column


' Sorts by Item Name, Dept, Status# Macro



' sorts on DeptID & StatusID & Item Name
With ActiveSheet
Set Rng = .Range(.Cells(1, 1), .Cells(Rows.Count, .Cells(1,
Columns.Count).End(xlToLeft)).End(xlUp))
'Set Rng = .Range(.Cells(1, 1), .Cells(Rows.Count, 25).End(xlUp))
Set rng1 = Rng.Columns(16).Cells
Set rng1 = rng1.Offset(1, 0).Resize(rng1.Count - 1)
For Each cell In rng1
cell.NumberFormat = "General"
cell.Value = CLng(cell.Value)
Next
Set rng1 = Rng.Columns(19).Cells
Set rng1 = rng1.Offset(1, 0).Resize(rng1.Count - 1)
For Each cell In rng1
cell.NumberFormat = "General"
cell.Value = CLng(cell.Value)
Next


MsgBox Rng.Address
Rng.Sort key1:=.Cells(1, 16), Order1:=xlAscending, _
key2:=.Cells(1, 19), Order2:=xlAscending, _
key3:=.Cells(1, 3), Order3:=xlAscending, Header:=xlYes, OrderCustom:=1,
MatchCase:=False, Orientation:=xlTopToBottom
End With

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default runtime 1004 error

Set Rng = .Range(.Cells(1, 1), .Cells(Rows.Count, .Cells(1,
Columns.Count).End(xlToLeft)).End(xlUp))

should be
Set rng = .Range(.Cells(1, 1), .Cells(Rows.Count, .Cells(1,
Columns.Count).End(xlToLeft).Column).End(xlUp))


to highlight the difference

..Cells(1, Columns.Count).End(xlToLeft)

should be

.Cells(1, Columns.Count).End(xlToLeft).Column
--
Regards,
Tom Ogilvy



Janis" wrote:

Here is the whole macro. There is a type mismatch on the first set range
presumably because it is not a range type variable. But if I change the
range variant type to range it does the same thing.
Thanks,


Public Sub CoerceAsNumDeptIDSort()

Dim Rng, rng1 As Range
Dim cell As Range
'finds the number of the last column


' Sorts by Item Name, Dept, Status# Macro



' sorts on DeptID & StatusID & Item Name
With ActiveSheet
Set Rng = .Range(.Cells(1, 1), .Cells(Rows.Count, .Cells(1,
Columns.Count).End(xlToLeft)).End(xlUp))
'Set Rng = .Range(.Cells(1, 1), .Cells(Rows.Count, 25).End(xlUp))
Set rng1 = Rng.Columns(16).Cells
Set rng1 = rng1.Offset(1, 0).Resize(rng1.Count - 1)
For Each cell In rng1
cell.NumberFormat = "General"
cell.Value = CLng(cell.Value)
Next
Set rng1 = Rng.Columns(19).Cells
Set rng1 = rng1.Offset(1, 0).Resize(rng1.Count - 1)
For Each cell In rng1
cell.NumberFormat = "General"
cell.Value = CLng(cell.Value)
Next


MsgBox Rng.Address
Rng.Sort key1:=.Cells(1, 16), Order1:=xlAscending, _
key2:=.Cells(1, 19), Order2:=xlAscending, _
key3:=.Cells(1, 3), Order3:=xlAscending, Header:=xlYes, OrderCustom:=1,
MatchCase:=False, Orientation:=xlTopToBottom
End With

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default runtime 1004 error

thanks, so it didn't know what object to go left of. Thanks again.

"Tom Ogilvy" wrote:

Set Rng = .Range(.Cells(1, 1), .Cells(Rows.Count, .Cells(1,
Columns.Count).End(xlToLeft)).End(xlUp))

should be
Set rng = .Range(.Cells(1, 1), .Cells(Rows.Count, .Cells(1,
Columns.Count).End(xlToLeft).Column).End(xlUp))


to highlight the difference

.Cells(1, Columns.Count).End(xlToLeft)

should be

.Cells(1, Columns.Count).End(xlToLeft).Column
--
Regards,
Tom Ogilvy



Janis" wrote:

Here is the whole macro. There is a type mismatch on the first set range
presumably because it is not a range type variable. But if I change the
range variant type to range it does the same thing.
Thanks,


Public Sub CoerceAsNumDeptIDSort()

Dim Rng, rng1 As Range
Dim cell As Range
'finds the number of the last column


' Sorts by Item Name, Dept, Status# Macro



' sorts on DeptID & StatusID & Item Name
With ActiveSheet
Set Rng = .Range(.Cells(1, 1), .Cells(Rows.Count, .Cells(1,
Columns.Count).End(xlToLeft)).End(xlUp))
'Set Rng = .Range(.Cells(1, 1), .Cells(Rows.Count, 25).End(xlUp))
Set rng1 = Rng.Columns(16).Cells
Set rng1 = rng1.Offset(1, 0).Resize(rng1.Count - 1)
For Each cell In rng1
cell.NumberFormat = "General"
cell.Value = CLng(cell.Value)
Next
Set rng1 = Rng.Columns(19).Cells
Set rng1 = rng1.Offset(1, 0).Resize(rng1.Count - 1)
For Each cell In rng1
cell.NumberFormat = "General"
cell.Value = CLng(cell.Value)
Next


MsgBox Rng.Address
Rng.Sort key1:=.Cells(1, 16), Order1:=xlAscending, _
key2:=.Cells(1, 19), Order2:=xlAscending, _
key3:=.Cells(1, 3), Order3:=xlAscending, Header:=xlYes, OrderCustom:=1,
MatchCase:=False, Orientation:=xlTopToBottom
End With

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default runtime 1004 error

No, as written it tried use the value of the last filled cell on the first
row as the column number.

If that cell has contained a number between 1 and 256 or valid column
letters, your code might have worked but probably not properly or failed on
some other line. Fortunately it failed on the troublesome line.

--
Regards,
Tom Ogilvy

"Janis" wrote:

thanks, so it didn't know what object to go left of. Thanks again.

"Tom Ogilvy" wrote:

Set Rng = .Range(.Cells(1, 1), .Cells(Rows.Count, .Cells(1,
Columns.Count).End(xlToLeft)).End(xlUp))

should be
Set rng = .Range(.Cells(1, 1), .Cells(Rows.Count, .Cells(1,
Columns.Count).End(xlToLeft).Column).End(xlUp))


to highlight the difference

.Cells(1, Columns.Count).End(xlToLeft)

should be

.Cells(1, Columns.Count).End(xlToLeft).Column
--
Regards,
Tom Ogilvy



Janis" wrote:

Here is the whole macro. There is a type mismatch on the first set range
presumably because it is not a range type variable. But if I change the
range variant type to range it does the same thing.
Thanks,


Public Sub CoerceAsNumDeptIDSort()

Dim Rng, rng1 As Range
Dim cell As Range
'finds the number of the last column


' Sorts by Item Name, Dept, Status# Macro



' sorts on DeptID & StatusID & Item Name
With ActiveSheet
Set Rng = .Range(.Cells(1, 1), .Cells(Rows.Count, .Cells(1,
Columns.Count).End(xlToLeft)).End(xlUp))
'Set Rng = .Range(.Cells(1, 1), .Cells(Rows.Count, 25).End(xlUp))
Set rng1 = Rng.Columns(16).Cells
Set rng1 = rng1.Offset(1, 0).Resize(rng1.Count - 1)
For Each cell In rng1
cell.NumberFormat = "General"
cell.Value = CLng(cell.Value)
Next
Set rng1 = Rng.Columns(19).Cells
Set rng1 = rng1.Offset(1, 0).Resize(rng1.Count - 1)
For Each cell In rng1
cell.NumberFormat = "General"
cell.Value = CLng(cell.Value)
Next


MsgBox Rng.Address
Rng.Sort key1:=.Cells(1, 16), Order1:=xlAscending, _
key2:=.Cells(1, 19), Order2:=xlAscending, _
key3:=.Cells(1, 3), Order3:=xlAscending, Header:=xlYes, OrderCustom:=1,
MatchCase:=False, Orientation:=xlTopToBottom
End With

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
runtime error '1004' Steve Excel Discussion (Misc queries) 1 April 28th 06 08:58 PM
Keep getting runtime error 1004 [email protected] Excel Programming 8 October 11th 05 02:02 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Runtime error 1004 edreczk Excel Programming 1 November 4th 04 10:19 PM
runtime error 1004 Adella Excel Programming 2 July 29th 03 08:07 PM


All times are GMT +1. The time now is 09:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"