Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 115
Default Sum used in macro where range stops at first non numerical cell

Is there anyway to include in a macro a sum up to the first non numerical
cell? Or in ohter words the size or name of the range varies each time you
use the macro.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,510
Default Sum used in macro where range stops at first non numerical cell

Hi Carol,

Try the following. Note that blank cells evaluate as zero and are therefore
numeric and hense the testing for numeric as well as for blanks.

Sub SumNumeric()

Dim iFirst As Long
Dim iLast As Long
Dim sumTotal

iFirst = 2
iLast = iFirst

'Tests cells for numeric and not blank
'in column A starting at row 2
Do While IsNumeric(Cells(iLast, "A")) _
And Cells(iLast, "A") < ""

iLast = iLast + 1
Loop

'iLast will be one greater than required number
'because it increments after the test
'so reduce value by 1
iLast = iLast - 1

sumTotal = WorksheetFunction _
.Sum(Range(Cells(iFirst, "A"), _
Cells(iLast, "A")))

End Sub

--
Regards,

OssieMac


"Carol" wrote:

Is there anyway to include in a macro a sum up to the first non numerical
cell? Or in ohter words the size or name of the range varies each time you
use the macro.

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
Macro stops working when sheet is protected RefLib1978 Excel Discussion (Misc queries) 3 May 28th 09 03:57 PM
Opening a file stops a Macro Bob Myers Excel Worksheet Functions 2 January 8th 08 11:50 PM
Macro stops at random places. Jeff Excel Discussion (Misc queries) 0 May 16th 07 02:38 AM
Macro repeats and then stops Sabba Efie Excel Discussion (Misc queries) 2 August 15th 06 11:03 PM
Vb macro stops when I try to create more than 89 charts Tiberius Charts and Charting in Excel 0 January 19th 06 05:52 PM


All times are GMT +1. The time now is 02:43 AM.

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"