Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Sum an R1C1 Range

I am attempting to sum the range selected by this code:
With Sheets("Sheet1")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

Thanks in advance for your help!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Sum an R1C1 Range

One way

For Each c In Selection
If (IsNumeric(c)) Then total = total + c.Value
Next


Mike

"Cinque Terra" wrote:

I am attempting to sum the range selected by this code:
With Sheets("Sheet1")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

Thanks in advance for your help!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Sum an R1C1 Range

Execellent - Thank you!

May I ask a follow-on question? I need to calculate a ratio between the
same range on two different sheets. In the code that follows, WriteSum
evaluates perfectly. But the code fails to select the range on the second
sheet. Any thoughts?

My code:
With Sheets("sheet1")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

For Each c In Selection
If (IsNumeric(c)) Then WriteSum = WriteSum + c.Value
Next

With Sheets("sheet2")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

For Each c In Selection
If (IsNumeric(c)) Then GridSum = GridSum + c.Value
Next

Ratio = (txt_SpreadAmt.Value - GridSum + WriteSum) / WriteSum


"Mike H" wrote:

One way

For Each c In Selection
If (IsNumeric(c)) Then total = total + c.Value
Next


Mike

"Cinque Terra" wrote:

I am attempting to sum the range selected by this code:
With Sheets("Sheet1")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

Thanks in advance for your help!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Sum an R1C1 Range

I figured it out. If I select sheet 2 before
With Sheets("sheet2")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

it works.

Whoo Hoo!

"Cinque Terra" wrote:

Execellent - Thank you!

May I ask a follow-on question? I need to calculate a ratio between the
same range on two different sheets. In the code that follows, WriteSum
evaluates perfectly. But the code fails to select the range on the second
sheet. Any thoughts?

My code:
With Sheets("sheet1")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

For Each c In Selection
If (IsNumeric(c)) Then WriteSum = WriteSum + c.Value
Next

With Sheets("sheet2")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

For Each c In Selection
If (IsNumeric(c)) Then GridSum = GridSum + c.Value
Next

Ratio = (txt_SpreadAmt.Value - GridSum + WriteSum) / WriteSum


"Mike H" wrote:

One way

For Each c In Selection
If (IsNumeric(c)) Then total = total + c.Value
Next


Mike

"Cinque Terra" wrote:

I am attempting to sum the range selected by this code:
With Sheets("Sheet1")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

Thanks in advance for your help!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Sum an R1C1 Range

Yes that's trght but be careful you must also select sheet 1 even if it's
already selected or the code may fail on a second run

Mike

"Cinque Terra" wrote:

I figured it out. If I select sheet 2 before
With Sheets("sheet2")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

it works.

Whoo Hoo!

"Cinque Terra" wrote:

Execellent - Thank you!

May I ask a follow-on question? I need to calculate a ratio between the
same range on two different sheets. In the code that follows, WriteSum
evaluates perfectly. But the code fails to select the range on the second
sheet. Any thoughts?

My code:
With Sheets("sheet1")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

For Each c In Selection
If (IsNumeric(c)) Then WriteSum = WriteSum + c.Value
Next

With Sheets("sheet2")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

For Each c In Selection
If (IsNumeric(c)) Then GridSum = GridSum + c.Value
Next

Ratio = (txt_SpreadAmt.Value - GridSum + WriteSum) / WriteSum


"Mike H" wrote:

One way

For Each c In Selection
If (IsNumeric(c)) Then total = total + c.Value
Next


Mike

"Cinque Terra" wrote:

I am attempting to sum the range selected by this code:
With Sheets("Sheet1")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

Thanks in advance for your help!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Sum an R1C1 Range

You don't need to select the range to get the sum:

Dim mySum as double

With Sheets("Sheet1")
mysum = application.sum(.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)))
End With
msgbox mysum

Cinque Terra wrote:

I am attempting to sum the range selected by this code:
With Sheets("Sheet1")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

Thanks in advance for your help!


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Sum an R1C1 Range

Nicely written - thanks!

"Dave Peterson" wrote:

You don't need to select the range to get the sum:

Dim mySum as double

With Sheets("Sheet1")
mysum = application.sum(.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)))
End With
msgbox mysum

Cinque Terra wrote:

I am attempting to sum the range selected by this code:
With Sheets("Sheet1")
.Range(.Cells(Row1, Col1), .Cells(Row2, Col2)).Select
End With

Thanks in advance for your help!


--

Dave Peterson

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
Setting Range Name using R1C1 needVBAhelp Excel Programming 2 November 9th 07 12:37 AM
Range selection with R1C1 Adam1 Chicago Excel Discussion (Misc queries) 6 November 8th 07 04:02 PM
Discontinuous Range via VBA using R1C1? (PeteCresswell) Excel Programming 7 December 2nd 06 01:12 AM
Using R1C1 in VB to select a range Robert_L_Ross Excel Programming 2 December 17th 05 07:45 AM
R1C1 to Range Jahson Excel Programming 3 February 17th 04 12:29 PM


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