#1   Report Post  
Posted to microsoft.public.excel.programming
tjh tjh is offline
external usenet poster
 
Posts: 96
Default Sum

Hello,

Is there and easy way to total values using vba.

I have a spreadsheet with a few thousand rows and I would like VBA to go
through the worksheet, and for anything that has RS in column L -- I want it
to take the value in columns P thru AA and sum them at the bottom and also
include the formula to the cell reference. A different total for each column.

Thanks,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Sum

Try this code

Sub Test()
Dim iLastRow As Long
Dim i As Long

For i = 16 To 27
iLastRow = Cells(Rows.Count, i).End(xlUp).Row
If iLastRow = 1 And Cells(1, i).Value = "" Then
Else
Cells(iLastRow + 1, i).FormulaR1C1 = _
"=SUMIF(R1C12:R" & iLastRow & "C12,""RS"",R1C" & _
i & ":R" & iLastRow & "C" & i & ")"
End If
Next i

End Sub


--
HTH

Bob Phillips

"tjh" wrote in message
...
Hello,

Is there and easy way to total values using vba.

I have a spreadsheet with a few thousand rows and I would like VBA to go
through the worksheet, and for anything that has RS in column L -- I want

it
to take the value in columns P thru AA and sum them at the bottom and also
include the formula to the cell reference. A different total for each

column.

Thanks,



  #3   Report Post  
Posted to microsoft.public.excel.programming
tjh tjh is offline
external usenet poster
 
Posts: 96
Default Sum

Thats great thanks,

One more question -- How about if the column L cell does not contain "RS"
and is not blank




"Bob Phillips" wrote:

Try this code

Sub Test()
Dim iLastRow As Long
Dim i As Long

For i = 16 To 27
iLastRow = Cells(Rows.Count, i).End(xlUp).Row
If iLastRow = 1 And Cells(1, i).Value = "" Then
Else
Cells(iLastRow + 1, i).FormulaR1C1 = _
"=SUMIF(R1C12:R" & iLastRow & "C12,""RS"",R1C" & _
i & ":R" & iLastRow & "C" & i & ")"
End If
Next i

End Sub


--
HTH

Bob Phillips

"tjh" wrote in message
...
Hello,

Is there and easy way to total values using vba.

I have a spreadsheet with a few thousand rows and I would like VBA to go
through the worksheet, and for anything that has RS in column L -- I want

it
to take the value in columns P thru AA and sum them at the bottom and also
include the formula to the cell reference. A different total for each

column.

Thanks,




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



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