run time error 1004:select method of range class failed.

J

JMCN

hello

i'm currently converting the excel 97 macros to excel 2003. i have the
following run time error 1004: select method of range class failed.

code is below... there's more to the code but for starters... it
errors on the
"Range("B2").Select ". i don't understand if the range contains the
data then why is there an error message that the range class failed in
excel 2003?

any advise would be appreciated.
thanks - jung

***************************************
Dim lastrow As Integer

If Workbooks.Count <> 2 Then
Beep
MsgBox "FUNCTION CANCELLED! " + Chr$(13) + Chr$(13) & "The
Macro workbook and the workbook to be formatted should be the only
workbooks open.", vbCritical
Exit Sub
End If

'determine last row of data
ActiveWindow.ActivateNext
lastrow = Range("A65536").End(xlUp).Row

'General formatting
ActiveWindow.Zoom = 75
Cells.Font.Name = "Arial"

Range("B2").Select 'run-time error 1004: select method of range class
failed.
ActiveWindow.FreezePanes = True
Rows("2:" & lastrow).Sort Key1:=Range("A2"), Order1:=xlAscending,
Key2:=Range("B2") _
, Order2:=xlAscending, Header:=xlNo, OrderCustom:=1,
MatchCase:=False, _
Orientation:=xlTopToBottom

'Column Header formatting
Range("A1:N1").Select
Selection.Font.ColorIndex = 5
Selection.Font.Bold = True
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
End With
Range("M1") = "Days Int Due"
Range("N1") = "Days Prin Due"
Rows("1:1").RowHeight = 39

'rest of code....
 
T

Tom Ogilvy

If this worked in xl97, I wouldn't expect a problem up to where you show the
error. the cause I would suspect is that you have the code in a sheet
module or the thisworkbook module. If that is the case, then move it to a
general module - but if you had it in the same place in xl97, I would have
expected an error there as well. Either that or the workbooks are in
reverse order when you run it.
 
J

JMCN

Tom Ogilvy said:
If this worked in xl97, I wouldn't expect a problem up to where you show the
error. the cause I would suspect is that you have the code in a sheet
module or the thisworkbook module. If that is the case, then move it to a
general module - but if you had it in the same place in xl97, I would have
expected an error there as well. Either that or the workbooks are in
reverse order when you run it.
hi tom,

i realized that i need to insert "ActiveSheet." before the
Range("B2").Select

thanks again!!
cheers - jung
 

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