Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
RPW RPW is offline
external usenet poster
 
Posts: 52
Default Why this "error 9"?

Hi all,

The snippet of code below stops on the first line that uses "UsedRange2".
The snippet is a duplicate of a prior snippet in the same Sub that does run
OK (I've changed variable names to have the number 2 at then end of the name
for this second snippet and 3 for the third copy). I can't see why this
would stop with the "subscript out of range - error 9" error. Can anyone
help?

For Each WkSht1 In OldWB1.Worksheets
SheetName = WkSht1.Name
If SheetName = "Blank Form" Then
Else
<< (stops on this line) Set UsedRange2 =
Sheets(WkSht1.Name).Range("K29:K32,K36:K44")
For Each cell In UsedRange2
SumArray2(MyCell2) = SumArray2(MyCell2) + cell.Value
Next cell
MyCell2 = MyCell2 + 1
End If
Next WkSht1
--
rpw
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Why this "error 9"?

Try this...

For Each WkSht1 In OldWB1.Worksheets
SheetName = WkSht1.Name
If SheetName = "Blank Form" Then
Else
Set UsedRange2 = WkSht1.Range("K29:K32,K36:K44")
For Each cell In UsedRange2
SumArray2(MyCell2) = SumArray2(MyCell2) + cell.Value
Next cell
MyCell2 = MyCell2 + 1
End If
Next WkSht1
--
HTH...

Jim Thomlinson


"rpw" wrote:

Hi all,

The snippet of code below stops on the first line that uses "UsedRange2".
The snippet is a duplicate of a prior snippet in the same Sub that does run
OK (I've changed variable names to have the number 2 at then end of the name
for this second snippet and 3 for the third copy). I can't see why this
would stop with the "subscript out of range - error 9" error. Can anyone
help?

For Each WkSht1 In OldWB1.Worksheets
SheetName = WkSht1.Name
If SheetName = "Blank Form" Then
Else
<< (stops on this line) Set UsedRange2 =
Sheets(WkSht1.Name).Range("K29:K32,K36:K44")
For Each cell In UsedRange2
SumArray2(MyCell2) = SumArray2(MyCell2) + cell.Value
Next cell
MyCell2 = MyCell2 + 1
End If
Next WkSht1
--
rpw

  #3   Report Post  
Posted to microsoft.public.excel.programming
RPW RPW is offline
external usenet poster
 
Posts: 52
Default Why this "error 9"?

That did it - thanks for the help!
--
rpw


"Jim Thomlinson" wrote:

Try this...

For Each WkSht1 In OldWB1.Worksheets
SheetName = WkSht1.Name
If SheetName = "Blank Form" Then
Else
Set UsedRange2 = WkSht1.Range("K29:K32,K36:K44")
For Each cell In UsedRange2
SumArray2(MyCell2) = SumArray2(MyCell2) + cell.Value
Next cell
MyCell2 = MyCell2 + 1
End If
Next WkSht1
--
HTH...

Jim Thomlinson


"rpw" wrote:

Hi all,

The snippet of code below stops on the first line that uses "UsedRange2".
The snippet is a duplicate of a prior snippet in the same Sub that does run
OK (I've changed variable names to have the number 2 at then end of the name
for this second snippet and 3 for the third copy). I can't see why this
would stop with the "subscript out of range - error 9" error. Can anyone
help?

For Each WkSht1 In OldWB1.Worksheets
SheetName = WkSht1.Name
If SheetName = "Blank Form" Then
Else
<< (stops on this line) Set UsedRange2 =
Sheets(WkSht1.Name).Range("K29:K32,K36:K44")
For Each cell In UsedRange2
SumArray2(MyCell2) = SumArray2(MyCell2) + cell.Value
Next cell
MyCell2 = MyCell2 + 1
End If
Next WkSht1
--
rpw

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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Shortcut key for "Paste Options" and "Error Checking" buttons? johndog Excel Discussion (Misc queries) 1 October 6th 06 11:56 AM
What is Error "Method "Paste" of object "_Worksheet" failed? vat Excel Programming 7 February 17th 06 08:05 PM
"Clean Me" Macro is giving "#VALUE!" error in the Notes field. Ryan Watkins Excel Programming 1 June 11th 05 12:25 AM
Getting "compile error" "method or data member not found" on reinstall Bp Excel Programming 1 April 23rd 04 04:42 PM


All times are GMT +1. The time now is 06:34 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"