![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Apr 2002
Location: Indianapolis
Posts: 80
|
I'm attempting to use a value returned by a dcount in a sum routine. I recorded the sum macro and then attempted to replace the number of rows up offset with the dcount value preceded by a "-". I'm getting an error (application-defined or object-defined error).... here's the code:
Sub Macro2() Dim i As Long i = Sheets("information").Range("bcount").Value Application.Goto Reference:="dr_91" ActiveCell.FormulaR1C1 = "=SUM(R[-i]C:R[-1]C)" ActiveCell.Offset(1, 0).Range("A1").Select End Sub Any suggestions would be greatly appreciated. Thanks! Lisa |
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
|
Quote:
Change the line to read ActiveCell.FormulaR1C1 = "=SUM(R[-" & i & "]C:R[-1]C)" HTH, Jay |
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Apr 2002
Location: Indianapolis
Posts: 80
|
Thanks so much, Jay!
Works perfectly. So, it's necessary to insert text into functions like this, even when referring to a value? (Trying to get the concepts hammered home...) Lisa |
|
|
|
|
|
#4 | |
|
MrExcel MVP
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
|
Quote:
What you are doing in "building" the formula in the worksheet as if you were typing it in. That requires it to be entered as 'text' so your -i addition actually put '-i' in the formula on the worksheet. Here, you have to separate the "text" you type on the worksheet from the value you want coded into the formula. Hope this helps, Jay |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|