Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Calculating Non-Constant Values in Cells


After importing a file from Access to Excel, and formatting the
spreadsheet, I need to calculate a sum. The problem is that the cell
references do not remain the same. The amount of rows to add depend on
the information being imported.

In the Macro, I have accessed the correct cell for the calculation by
the "EndDown" feature. I then press the sum key on the toolbar, but it
keeps the same count of rows to sum, which I mentioned differs. Is
there a way to sum the rows with variance each time? Below is what I
have coded for one column.

(The cell "O11" is always the beginning cell for the calculation.)
Range("O11").Select
Selection.End(xlDown).Select
ActiveCell.FormulaR1C1 = "=SUM(R[-7]C:R[-1]C)"

I appreciate any help available!!
Shelley


--
sesmith
------------------------------------------------------------------------
sesmith's Profile: http://www.excelforum.com/member.php...o&userid=24765
View this thread: http://www.excelforum.com/showthread...hreadid=384563

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Calculating Non-Constant Values in Cells

Hi,
I am sure there is a more elegant solution but the following works!

Sub sumvar(rng)

Dim v As Variant
Dim sr As Long, fr As Long

rng.Select
sr = Selection.Row ' Start row
v = Split(rng.Address(columnAbsolute:=False), "$") ' Column letter
Selection.End(xlDown).Select ' Last row of data to be summed
fr = Selection.Row ' finish row
' SUM in next row .....
ActiveCell.Offset(1, 0).Formula = "=SUM(" & v(0) & sr & ":" & v(0) & fr & ")"
End Sub

Sub test()
Call sumvar(Range("AB1"))
End Sub


HTH

"sesmith" wrote:


After importing a file from Access to Excel, and formatting the
spreadsheet, I need to calculate a sum. The problem is that the cell
references do not remain the same. The amount of rows to add depend on
the information being imported.

In the Macro, I have accessed the correct cell for the calculation by
the "EndDown" feature. I then press the sum key on the toolbar, but it
keeps the same count of rows to sum, which I mentioned differs. Is
there a way to sum the rows with variance each time? Below is what I
have coded for one column.

(The cell "O11" is always the beginning cell for the calculation.)
Range("O11").Select
Selection.End(xlDown).Select
ActiveCell.FormulaR1C1 = "=SUM(R[-7]C:R[-1]C)"

I appreciate any help available!!
Shelley


--
sesmith
------------------------------------------------------------------------
sesmith's Profile: http://www.excelforum.com/member.php...o&userid=24765
View this thread: http://www.excelforum.com/showthread...hreadid=384563


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Calculating Non-Constant Values in Cells


HTH,

I tried that, but it didn't work for me. Is there part of the code I
should be changing? It's throwing an error out at the Sum calculation
and placing the active cell as the very last cell available for the
entire spreadsheet. Help?!

Sincerely,
Shelley


--
sesmith
------------------------------------------------------------------------
sesmith's Profile: http://www.excelforum.com/member.php...o&userid=24765
View this thread: http://www.excelforum.com/showthread...hreadid=384563

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Calculating Non-Constant Values in Cells

Hi,
My testing ( for example) I had data in rows 11 to 17, and SUM was
in row 18. Another test I had data in rows 1 to 10, and SUM was in 11.
Repeated running of the macro calculated SUM in the next row down i.e. 11, 12
,13.

I assumed the data was contiguous and I cannot see why it goes to the end
cell. No manual intervention is required to select the SUM cell - the macro
does it for you..

If there are blanks in the data, the SUM will be in the first blank cell it
meets. You could change this by using:

fr = Cells(Rows.Count, v(0)).End(xlUp).Row
Cells(fr, v(0)).Select

Try this.

HTH

"sesmith" wrote:


HTH,

I tried that, but it didn't work for me. Is there part of the code I
should be changing? It's throwing an error out at the Sum calculation
and placing the active cell as the very last cell available for the
entire spreadsheet. Help?!

Sincerely,
Shelley


--
sesmith
------------------------------------------------------------------------
sesmith's Profile: http://www.excelforum.com/member.php...o&userid=24765
View this thread: http://www.excelforum.com/showthread...hreadid=384563


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Calculating Non-Constant Values in Cells


THT,

You have been such a blessing! All I needed to do was change the rang
that was first selected. (I should've known that!) It works perfectl
and my project is now completed.

THANKS AGAIN!
Shelley :

--
sesmit
-----------------------------------------------------------------------
sesmith's Profile: http://www.excelforum.com/member.php...fo&userid=2476
View this thread: http://www.excelforum.com/showthread.php?threadid=38456



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Calculating Non-Constant Values in Cells

Glad to have been of service and that is all fixed.

"sesmith" wrote:


THT,

You have been such a blessing! All I needed to do was change the range
that was first selected. (I should've known that!) It works perfectly
and my project is now completed.

THANKS AGAIN!
Shelley :)


--
sesmith
------------------------------------------------------------------------
sesmith's Profile: http://www.excelforum.com/member.php...o&userid=24765
View this thread: http://www.excelforum.com/showthread...hreadid=384563


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
calculate values in an unlimited range of cells in a column WITHOUTalso calculating values that had previously been filtered AGAINST? yadang Excel Discussion (Misc queries) 2 October 1st 09 06:18 PM
How do I keep the divisor constant in calculating percentage remai clpayne Excel Discussion (Misc queries) 3 June 29th 09 10:30 PM
How to use date for calculating values in other cells Bamboozled Excel Worksheet Functions 2 October 17th 08 06:14 PM
Keep lookup values constant tommcbrny Excel Discussion (Misc queries) 5 October 26th 06 05:53 PM
Excel displaying formulae as constant and not calculating formula gpbell Excel Worksheet Functions 2 February 16th 06 08:26 AM


All times are GMT +1. The time now is 03:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"