Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Defining a formula

HI,
I have a block of data in one worksheet and I am trying to have VBA write a
formula in a different worksheet. The range to be used in the formula is
not static. Based on some other VBA coding I find the rows bounding the
range to be used in the formula. When the macro is run I get an error in the
cell that contains the formula.

In this example the data is in the worksheet "EstimatedNEEDaylight"
From the other coding I have found that the range should be from E2 to E74.
The column E and row 2 are constants, but the row 74 is the real dynamic part
so was stored in the variable greenuprow

The VBA code I am trying run looks like the following

ActiveCell.FormulaR1C1 = "=Sum(EstimatedNEEDaylight!E2:E" & greenuprow & ")"

The resulting formula that is placed in the cell that gives the error is
=Sum(EstimatedNEEDaylight!'E2':'E74')

I have tried a couple variation on the theme like creating a variable for
the sum parameter, but keep getting the same type of error. Also running the
VBA in Debug mode I can see the resulting formula looks correct
there.....that is should be
=Sum(EstimatedNEEDaylight!E2:E74)

Any ideas????
Thanks

--
Mark Mesarch
School of Natural Resources
University of Nebraska-Lincoln
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Defining a formula

Try changing the .formular1c1 to just plain old .formula.



MMesarch wrote:

HI,
I have a block of data in one worksheet and I am trying to have VBA write a
formula in a different worksheet. The range to be used in the formula is
not static. Based on some other VBA coding I find the rows bounding the
range to be used in the formula. When the macro is run I get an error in the
cell that contains the formula.

In this example the data is in the worksheet "EstimatedNEEDaylight"
From the other coding I have found that the range should be from E2 to E74.
The column E and row 2 are constants, but the row 74 is the real dynamic part
so was stored in the variable greenuprow

The VBA code I am trying run looks like the following

ActiveCell.FormulaR1C1 = "=Sum(EstimatedNEEDaylight!E2:E" & greenuprow & ")"

The resulting formula that is placed in the cell that gives the error is
=Sum(EstimatedNEEDaylight!'E2':'E74')

I have tried a couple variation on the theme like creating a variable for
the sum parameter, but keep getting the same type of error. Also running the
VBA in Debug mode I can see the resulting formula looks correct
there.....that is should be
=Sum(EstimatedNEEDaylight!E2:E74)

Any ideas????
Thanks

--
Mark Mesarch
School of Natural Resources
University of Nebraska-Lincoln


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Defining a formula

Sub gsnu()
Dim greenuprow As Integer, s As String
greenuprow = 74
s = "EstimatedNEEDaylight!E2:E" & greenuprow
ActiveCell.Formula = "=sum(" & s & ")"
End Sub

--
Gary''s Student


"MMesarch" wrote:

HI,
I have a block of data in one worksheet and I am trying to have VBA write a
formula in a different worksheet. The range to be used in the formula is
not static. Based on some other VBA coding I find the rows bounding the
range to be used in the formula. When the macro is run I get an error in the
cell that contains the formula.

In this example the data is in the worksheet "EstimatedNEEDaylight"
From the other coding I have found that the range should be from E2 to E74.
The column E and row 2 are constants, but the row 74 is the real dynamic part
so was stored in the variable greenuprow

The VBA code I am trying run looks like the following

ActiveCell.FormulaR1C1 = "=Sum(EstimatedNEEDaylight!E2:E" & greenuprow & ")"

The resulting formula that is placed in the cell that gives the error is
=Sum(EstimatedNEEDaylight!'E2':'E74')

I have tried a couple variation on the theme like creating a variable for
the sum parameter, but keep getting the same type of error. Also running the
VBA in Debug mode I can see the resulting formula looks correct
there.....that is should be
=Sum(EstimatedNEEDaylight!E2:E74)

Any ideas????
Thanks

--
Mark Mesarch
School of Natural Resources
University of Nebraska-Lincoln

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Defining a formula

Thanks. that did the trick
--
Mark Mesarch
School of Natural Resources
University of Nebraska-Lincoln


"MMesarch" wrote:

HI,
I have a block of data in one worksheet and I am trying to have VBA write a
formula in a different worksheet. The range to be used in the formula is
not static. Based on some other VBA coding I find the rows bounding the
range to be used in the formula. When the macro is run I get an error in the
cell that contains the formula.

In this example the data is in the worksheet "EstimatedNEEDaylight"
From the other coding I have found that the range should be from E2 to E74.
The column E and row 2 are constants, but the row 74 is the real dynamic part
so was stored in the variable greenuprow

The VBA code I am trying run looks like the following

ActiveCell.FormulaR1C1 = "=Sum(EstimatedNEEDaylight!E2:E" & greenuprow & ")"

The resulting formula that is placed in the cell that gives the error is
=Sum(EstimatedNEEDaylight!'E2':'E74')

I have tried a couple variation on the theme like creating a variable for
the sum parameter, but keep getting the same type of error. Also running the
VBA in Debug mode I can see the resulting formula looks correct
there.....that is should be
=Sum(EstimatedNEEDaylight!E2:E74)

Any ideas????
Thanks

--
Mark Mesarch
School of Natural Resources
University of Nebraska-Lincoln

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Defining a formula

You are very welcome Mark.
--
Gary''s Student


"MMesarch" wrote:

Thanks. that did the trick
--
Mark Mesarch
School of Natural Resources
University of Nebraska-Lincoln


"MMesarch" wrote:

HI,
I have a block of data in one worksheet and I am trying to have VBA write a
formula in a different worksheet. The range to be used in the formula is
not static. Based on some other VBA coding I find the rows bounding the
range to be used in the formula. When the macro is run I get an error in the
cell that contains the formula.

In this example the data is in the worksheet "EstimatedNEEDaylight"
From the other coding I have found that the range should be from E2 to E74.
The column E and row 2 are constants, but the row 74 is the real dynamic part
so was stored in the variable greenuprow

The VBA code I am trying run looks like the following

ActiveCell.FormulaR1C1 = "=Sum(EstimatedNEEDaylight!E2:E" & greenuprow & ")"

The resulting formula that is placed in the cell that gives the error is
=Sum(EstimatedNEEDaylight!'E2':'E74')

I have tried a couple variation on the theme like creating a variable for
the sum parameter, but keep getting the same type of error. Also running the
VBA in Debug mode I can see the resulting formula looks correct
there.....that is should be
=Sum(EstimatedNEEDaylight!E2:E74)

Any ideas????
Thanks

--
Mark Mesarch
School of Natural Resources
University of Nebraska-Lincoln

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
Name Defining Chris Excel Discussion (Misc queries) 2 August 10th 06 03:06 PM
defining a formula christine Excel Programming 1 March 31st 06 07:31 PM
formula for defining axis maximum and increments Nick Turner Charts and Charting in Excel 4 March 20th 05 09:59 PM
Defining Cell Row Value Remotely in Formula not Code Danny[_6_] Excel Programming 1 May 1st 04 08:16 PM
Defining a formula Bob Kilmer Excel Programming 0 July 24th 03 01:18 AM


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