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


I have the following code:

Dim G as Integer

G = Worksheets("Movies").WorksheetFunction.CountIf("AE :AE", "G")

I'm assuming I'm simply not using the CountIf function correctly but I keep
getting Subscript Out Of Range. What am I doing wrong?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Runtime Error 9


Hi,

Try this but note your criteria of G was invalid and subscriot out of range
could mean your sheet name Movies is spelt incorrectly

G = WorksheetFunction.CountIf(Sheets("Movies").Range(" AE:AE"),
Sheets("Movies").Range("G1"))

Mike

"Bishop" wrote:

I have the following code:

Dim G as Integer

G = Worksheets("Movies").WorksheetFunction.CountIf("AE :AE", "G")

I'm assuming I'm simply not using the CountIf function correctly but I keep
getting Subscript Out Of Range. What am I doing wrong?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Runtime Error 9


Still getting the same error. And I verified that the sheet name is spelled
correctly. Other ideas?

"Mike H" wrote:

Hi,

Try this but note your criteria of G was invalid and subscriot out of range
could mean your sheet name Movies is spelt incorrectly

G = WorksheetFunction.CountIf(Sheets("Movies").Range(" AE:AE"),
Sheets("Movies").Range("G1"))

Mike

"Bishop" wrote:

I have the following code:

Dim G as Integer

G = Worksheets("Movies").WorksheetFunction.CountIf("AE :AE", "G")

I'm assuming I'm simply not using the CountIf function correctly but I keep
getting Subscript Out Of Range. What am I doing wrong?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Runtime Error 9


Maybe the activeworkbook isn't what you expected.

Or your worksheet name isn't spelled correctly (check for leading/trailing
spaces, too!)

Bishop wrote:

Still getting the same error. And I verified that the sheet name is spelled
correctly. Other ideas?

"Mike H" wrote:

Hi,

Try this but note your criteria of G was invalid and subscriot out of range
could mean your sheet name Movies is spelt incorrectly

G = WorksheetFunction.CountIf(Sheets("Movies").Range(" AE:AE"),
Sheets("Movies").Range("G1"))

Mike

"Bishop" wrote:

I have the following code:

Dim G as Integer

G = Worksheets("Movies").WorksheetFunction.CountIf("AE :AE", "G")

I'm assuming I'm simply not using the CountIf function correctly but I keep
getting Subscript Out Of Range. What am I doing wrong?


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default Runtime Error 9

On 1 Iul, 23:51, Bishop wrote:
*Other ideas?


I think it cann't Dim G as Integer ,
maybe Dim G As Worksheet .


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Runtime Error 9


No more ideas, it works perfectly for me and subscript out of range is Excels
way of telling you it can't find something your telling it to look for

Mike

"Bishop" wrote:

Still getting the same error. And I verified that the sheet name is spelled
correctly. Other ideas?

"Mike H" wrote:

Hi,

Try this but note your criteria of G was invalid and subscriot out of range
could mean your sheet name Movies is spelt incorrectly

G = WorksheetFunction.CountIf(Sheets("Movies").Range(" AE:AE"),
Sheets("Movies").Range("G1"))

Mike

"Bishop" wrote:

I have the following code:

Dim G as Integer

G = Worksheets("Movies").WorksheetFunction.CountIf("AE :AE", "G")

I'm assuming I'm simply not using the CountIf function correctly but I keep
getting Subscript Out Of Range. What am I doing wrong?

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default Runtime Error 9

In the same time , Countif is looking for
criteria ,, G ,, , which have the same name
with your G variable , rename variable G with
another name .
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Runtime Error 9


That was it! When I made the Movies worksheet active (it wasn't before) it
worked. But I need this in a With block. I tried this:

With Worksheets("Movies")
G = .WorksheetFunction.CountIf(Sheets("Movies").Range( "AE:AE"),
Sheets("Movies").Range("G1"))

But that's not working. Will this work in a With block?

"Dave Peterson" wrote:

Maybe the activeworkbook isn't what you expected.

Or your worksheet name isn't spelled correctly (check for leading/trailing
spaces, too!)

Bishop wrote:

Still getting the same error. And I verified that the sheet name is spelled
correctly. Other ideas?

"Mike H" wrote:

Hi,

Try this but note your criteria of G was invalid and subscriot out of range
could mean your sheet name Movies is spelt incorrectly

G = WorksheetFunction.CountIf(Sheets("Movies").Range(" AE:AE"),
Sheets("Movies").Range("G1"))

Mike

"Bishop" wrote:

I have the following code:

Dim G as Integer

G = Worksheets("Movies").WorksheetFunction.CountIf("AE :AE", "G")

I'm assuming I'm simply not using the CountIf function correctly but I keep
getting Subscript Out Of Range. What am I doing wrong?


--

Dave Peterson

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Runtime Error 9


hi,

However you got my code to work it wasn't by making Movies the active sheet
because it doesn't need to be active if the sheet is explicitly named in the
code. the correct syntax for what your trying to do now is

With Worksheets("Movies")
G = WorksheetFunction.CountIf(.Range("AE:AE"), .Range("G1"))
End With


Mike

"Bishop" wrote:

That was it! When I made the Movies worksheet active (it wasn't before) it
worked. But I need this in a With block. I tried this:

With Worksheets("Movies")
G = .WorksheetFunction.CountIf(Sheets("Movies").Range( "AE:AE"),
Sheets("Movies").Range("G1"))

But that's not working. Will this work in a With block?

"Dave Peterson" wrote:

Maybe the activeworkbook isn't what you expected.

Or your worksheet name isn't spelled correctly (check for leading/trailing
spaces, too!)

Bishop wrote:

Still getting the same error. And I verified that the sheet name is spelled
correctly. Other ideas?

"Mike H" wrote:

Hi,

Try this but note your criteria of G was invalid and subscriot out of range
could mean your sheet name Movies is spelt incorrectly

G = WorksheetFunction.CountIf(Sheets("Movies").Range(" AE:AE"),
Sheets("Movies").Range("G1"))

Mike

"Bishop" wrote:

I have the following code:

Dim G as Integer

G = Worksheets("Movies").WorksheetFunction.CountIf("AE :AE", "G")

I'm assuming I'm simply not using the CountIf function correctly but I keep
getting Subscript Out Of Range. What am I doing wrong?


--

Dave Peterson

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' application or object defined error Janis Excel Programming 4 November 18th 09 03:01 PM
runtime error 13 - type mismatch error in Excel 97 on Citrix Kevin Maher Excel Programming 7 March 8th 08 11:48 AM
runtime error '1004' application or object defined error. Please help deej Excel Programming 0 August 1st 07 09:26 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Syntax Error Runtime Error '424' Object Required sjenks183 Excel Programming 1 January 23rd 04 09:25 AM


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