View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Nick Hodge Nick Hodge is offline
external usenet poster
 
Posts: 1,173
Default Macro Totaling a Column of Numbers

Colibri

Not sure I totally understand but you could use a Worksheet_Selection change
event,like below. (To invoke right click the sheet tab with the data and
select view code... and paste here). This will add a total to the last entry
on a column that is clicked on providing the data in the column is
contiguous (no gaps)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim colNum As Integer, lLastRow As Long
Dim dTotal As Double
colNum = Target.Column
lLastRow = Application.WorksheetFunction.CountA(Columns(Targe t.Column))
dTotal = Application.WorksheetFunction.Sum(Columns(Target.C olumn))
Cells(lLastRow + 1, Target.Column).Value = dTotal
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


wrote in message
oups.com...
OK, all, here's the scenario: I have a spreadsheet with 20 of columns.
Half of the columns have numbers in them. The columns are of different
lengths so some have 35 rows, some have 65 rows. I want to have a
macro whereby I can click on the first cell in the column (ie Colmn B)
that has a digit and the macro will add all the numbers in that column
and place the total at the next available cell at the bottom of the
column (ie in cell B37). Then, I want to move to a DIFFERENT column
(Column D) that has 65 numbers in it, run the macro and it will also
add up all the numbers in THAT column and place the total in the next
available cell (Cell D67) at the bottom of the column. And on and on
withthe rest of the columns with numbers. Does my question make sense
and is it possible?