Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default "Subscript out of range Runtime Error 9"

In the code below I get message "Subscript out of range Runtime Error 9"
I think it's to do with the asterisked line, not too sure.

The only worksheets I have are "J" AND "J2"

Sub desI()
Worksheets.Add.Name = "Changes"
k = 2
For i = 1 To 200
For j = 1 To 200
** If Worksheets("J").Cells(i, j) < Worksheets("J2").Cells(i, j) Then
Worksheets("J").Cells(i, j).EntireRow.Copy _
Destination:=Worksheets("Changes").Cells(k, 1)
Worksheets("J2").Cells(i, j).EntireRow.Copy _
Destination:=Worksheets("Changes").Cells(k + 1, 1)
With Worksheets("Changes")
.Cells(k + 1, 1).ClearContents
For m = 2 To 20
.Cells(k + 2, m).Value = .Cells(k, m) - .Cells(k + 1, m)
With .Cells(k + 2, m).borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Next m
End With
k = k + 4
Exit For
End If
Next j
Next i

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default "Subscript out of range Runtime Error 9"

Are you sure that 'J' and 'J2' are the actual names? No spaces?


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


"teresa" wrote in message
...
In the code below I get message "Subscript out of range Runtime
Error 9"
I think it's to do with the asterisked line, not too sure.

The only worksheets I have are "J" AND "J2"

Sub desI()
Worksheets.Add.Name = "Changes"
k = 2
For i = 1 To 200
For j = 1 To 200
** If Worksheets("J").Cells(i, j) < Worksheets("J2").Cells(i,
j) Then
Worksheets("J").Cells(i, j).EntireRow.Copy _
Destination:=Worksheets("Changes").Cells(k, 1)
Worksheets("J2").Cells(i, j).EntireRow.Copy _
Destination:=Worksheets("Changes").Cells(k + 1, 1)
With Worksheets("Changes")
.Cells(k + 1, 1).ClearContents
For m = 2 To 20
.Cells(k + 2, m).Value = .Cells(k, m) - .Cells(k + 1, m)
With .Cells(k + 2, m).borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Next m
End With
k = k + 4
Exit For
End If
Next j
Next i

End Sub




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
Error Message "Subscript our of range" gsmclang Excel Discussion (Misc queries) 1 April 5th 07 06:59 PM
Runtime Error "1004" Select Method of Range Class Failed Stephen[_7_] Excel Programming 4 April 10th 04 06:28 AM
strange "subscript out of range" error! behnood Excel Programming 3 February 17th 04 08:26 AM
SaveAs "subscript out of range" error (COM - SOAP) Matthia Excel Programming 0 July 11th 03 07:01 AM
SaveAs "subscript out of range" error (COM - SOAP) jaf Excel Programming 0 July 10th 03 07:59 PM


All times are GMT +1. The time now is 09:55 AM.

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"