Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default FormulaR1C1 gets strange application/object defined error

I am writing some code, and I need to use an array formula. I am
getting the strangest error, however, based on how I define the range
object that the FormulaR1C1 acts on. Here is an example: (Note: rst(0)
is a recordset object. PERIOD is a constant int that tells what columns
the PERIOD measurement is in)


---Example #1---

Sheets(i).Range("m2:m" & rst(0).RecordCount + 1). _
FormulaR1C1 = "=countif(periodRange,RC[" & PERIOD - _
rst(0).Fields.Count & "])"

'This is what I want to do, however, I DON'T want to refer to the
column by "m", 'since I have a variable with "13" in it that I want to
use instead. Note, the above code works PERFECTLY. The problem is the
"m" references.

---Example #2---

Sheets(i).Range("m2:m200"). _
FormulaR1C1 = "=countif(periodRange,RC[" & PERIOD _
- rst(0).Fields.Count & "])"

This code works fine also. Strangely enough, it only fills to 192ish (+
or - five records) for each sheet. I don't know why that is -- and its
not the problem -- but I thought I'd mention it just in case.

---Example #3---

Sheets(i).Range(Cells(2, 13), Cells(500, 13)). _
FormulaR1C1 = "=countif(periodRange,RC[" & PERIOD _
- rst(0).Fields.Count & "])"

This code DOES NOT work. It *should* be the same as #2, but I get an
"application-defined or object defined error". '

---Example #4---

Sheets(i).Range(Cells(2,rst(0).Fields.Count),_
Cells(rst(0).RecordCount + 1,rst(0).Fields.Count)) _
.FormulaR1C1 = "=countif(periodRange,RC[" & _
PERIOD - rst(0).Fields.Count & "])"

This is the code that I would LIKE to have. This should perfectly
replace Example #1. Again, however, I get application/object defined
error.
-----

Thanks in advance for your help. This is driving me nuts.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default FormulaR1C1 gets strange application/object defined error

With Sheets(i)
.Range(.Cells(2, 13), .Cells(500, 13)). _
FormulaR1C1 = "=countif(periodRange,RC[" & PERIOD _
- rst(0).Fields.Count & "])"
End With

You need to qualify Cells as well.

--
Regards,
Tom Ogilvy


"aspenbordr" wrote in message
oups.com...
I am writing some code, and I need to use an array formula. I am
getting the strangest error, however, based on how I define the range
object that the FormulaR1C1 acts on. Here is an example: (Note: rst(0)
is a recordset object. PERIOD is a constant int that tells what columns
the PERIOD measurement is in)


---Example #1---

Sheets(i).Range("m2:m" & rst(0).RecordCount + 1). _
FormulaR1C1 = "=countif(periodRange,RC[" & PERIOD - _
rst(0).Fields.Count & "])"

'This is what I want to do, however, I DON'T want to refer to the
column by "m", 'since I have a variable with "13" in it that I want to
use instead. Note, the above code works PERFECTLY. The problem is the
"m" references.

---Example #2---

Sheets(i).Range("m2:m200"). _
FormulaR1C1 = "=countif(periodRange,RC[" & PERIOD _
- rst(0).Fields.Count & "])"

This code works fine also. Strangely enough, it only fills to 192ish (+
or - five records) for each sheet. I don't know why that is -- and its
not the problem -- but I thought I'd mention it just in case.

---Example #3---

Sheets(i).Range(Cells(2, 13), Cells(500, 13)). _
FormulaR1C1 = "=countif(periodRange,RC[" & PERIOD _
- rst(0).Fields.Count & "])"

This code DOES NOT work. It *should* be the same as #2, but I get an
"application-defined or object defined error". '

---Example #4---

Sheets(i).Range(Cells(2,rst(0).Fields.Count),_
Cells(rst(0).RecordCount + 1,rst(0).Fields.Count)) _
.FormulaR1C1 = "=countif(periodRange,RC[" & _
PERIOD - rst(0).Fields.Count & "])"

This is the code that I would LIKE to have. This should perfectly
replace Example #1. Again, however, I get application/object defined
error.
-----

Thanks in advance for your help. This is driving me nuts.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default FormulaR1C1 gets strange application/object defined error

Perfect! Thanks for the help. Hard to believe I missed that one.

-Andrew

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
Run-time error '50290': Application-defined or object-defined erro Macro button Excel Discussion (Misc queries) 1 March 12th 09 10:59 AM
error: ActiveCell.Offset(0, -1).Select = Application-defined or object-defined error -[::::Shamran::::]- Excel Programming 7 June 7th 05 02:14 PM
Macro Run-time Error 1004 Application Defined or Object Defined Error Anddmx Excel Programming 6 June 9th 04 03:40 PM
Runtime Error 1004 -- Application Defined or Object Defined Error John[_51_] Excel Programming 3 September 4th 03 04:28 PM


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