Name error

Gregfox

Board Regular
Joined
Apr 12, 2011
Messages
120
Hi All,
The following code gives a name error in cell I2. Anyone know how I could fix it?
StartYear2018 is a named cell. Working with excel 2007 on a PC.
Code:
 Dim StartYear As Double
     StartYear = Range("StartYear2018")
     
 Range("I2").Select
 ActiveCell.FormulaR1C1 = "=+SUM(R[1]C: StartYear)"

Thanks.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
What value is StartYear and what are you wanting the formula to be?

Was looking at this but doesn't seem to make much sense to sum a cell.

Code:
Sub InsertRows()

 Dim StartYear As Double
     StartYear = Range("StartYear2018")
     
 Range("I2").Select
 ActiveCell.FormulaR1C1 = "=SUM(R[1]C" & StartYear2018 & ")"
    
End Sub
 
Last edited:
Upvote 0
I'm trying to sum all the numbers in cell from 'StartYear'(StartYear is a named cell) to R1 same column relative to I2 into I2.
Sorry I omitted a ':' in the last, the below is correct.
Rich (BB code):
Sub InsertRows() Dim StartYear As Double StartYear = Range("StartYear2018") Range("I2").Select ActiveCell.FormulaR1C1 = "=SUM(R[1]C:" & StartYear2018 & ")" End Sub

Thanks.
 
Upvote 0
To be more clear I want to sum all the cells in Col 'I' from I3 to Named cell StartYear in the same column, into I2.
Sorry I was not clear.
 
Last edited:
Upvote 0
Hi,
Try this:
Rich (BB code):
Sub MySum()
  Range("I2").Formula = "=SUM(I3:StartYear)"
End Sub
 
Upvote 0
:confused:
Well, it looked good on paper, but when I tried it I got the same NAME ERROR. I think it may have to do with the named cell??
Rich (BB code):
Sub SumI3()
     Dim StartYear As Double
     StartYear = Range("StartYear2018")


     Range("I2").Formula = "=SUM(StartYear:I3)"
End Sub
When I run the following it works but I really have to use a variable

Rich (BB code):
Sub SumI3()


     Range("I2").Formula = "=SUM(StartYear2018:I3)"
End Sub




[/code]
 
Last edited:
Upvote 0
Well,
What value is in the named cell StartYear2018?
What formula of the cell is expected being entered manually, not by the code?

 
Upvote 0
May be you mean this?
Rich (BB code):
Sub SetFormula()
  Dim NamedCell As String
  NamedCell = "StartYear2018"
  Range("I2").Formula = "=SUM(" & NamedCell & ":I3)"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top