Gregfox

Board Regular
Joined
Apr 12, 2011
Messages
120
Hi, When I run this I get a #NAME in I2. I would like to know what I'm doing wrong... Thanks!
BTW I there an easer way to do this?
Code:
Sub SumOfColumn()
'
'
'
Dim WithDraw As String  'named cell is WithDraw_2018
WithDraw = "WithDraw_2018"
   Sheets("sheet2").Select
    Range("I2").Select
    ActiveCell.FormulaR1C1 = "=+SUM(R[1]C:WithDraw)"
    Selection.NumberFormat = "$#,##0_);[Red]($#,##0)"
'
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
.
What is it you are attempting to do ? I understand you are wanting to place a formula in A1, but I don't understand the remainder of your code.
 
Upvote 0
maybe this

Code:
WithDraw = Range("withDraw").Address(0, 0)
With Sheets("sheet2").Range("I2")
   .Formula = "=SUM(C1:" & WithDraw & ")"
   .NumberFormat = "$#,##0_);[Red]($#,##0)"
End With
 
Upvote 0
This is a snip-it of a larger code, I wanted to put a single variable at the top of he code, so that when the year changes instead of changing 20 or 30 iterations in the code I could just change the variable.
Thanks
 
Upvote 0
This is a snip-it of a larger code, I wanted to put a single variable at the top of he code, so that when the year changes instead of changing 20 or 30 iterations in the code I could just change the variable.
Thanks
 
Upvote 0
Does the code provided not work ???
If this is a piece of a lerger code you should provide all of the code. It's very difficult to give you a solution if we only get part of the story !
 
Upvote 0
The code didn't work because you needed to specify the cell address, not the name of the cell required !
you also asked
BTW I there an easer way to do this?
which is why I provided the code.
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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