View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default How to Sum cells in a variable raw using VBA?

Is N10 just an example, this is where the variability might lie?

To get the last row

cLastRow = Cells(Rows.Count,"N").End(xlUp).Row

To sum them

theSum = WorksheetFunction.Sum(Range("N4:N" & CLastRow)

To test D10

With Range("N" & cLastRow+1)
if Range("D10").Value = "" Then
.Value = WorksheetFunction.Sum(Range("N4:N" & CLastRow)
Else
.Value = Range("L" & cLastRow+1).Value + Range("M" &
cLastRow+1).Value
End If
End With

--

HTH

RP
(remove nothere from the email address if mailing direct)


"IJQ" wrote in message
...
Summing Cells in a Variable Raw
I am trying to Sum up cell contents in a variable raw, meaning cells in
column N are to be added, but the no of raws may vary. I want to specify

Two
conditions to Sum these cells , for example if cell D10="", then Sum all
cells between N4 and N9, assuming that cells N1 up to N3 have already been
Summed up by the macro, otherwise the cell value in N10 is the Product of
L10*M10.
Any Suggestions, Please.