Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Sean Anderson   on Sep 24 In MS Office Category.

  
Question Answered By: Debbie Reyes   on Sep 24

I'm not sure why you've mentioned column B, as you never use it again. I
suspect that your explanation might be incorrect. However, I've taken it
exactly as you had it. I.e. use the selected range to position a formula in
C at the bottom of the selection and the sum is from column A. I'm also
assuming that the number you want to divide by is in F1.

Option Explicit

Private Sub CommandButton1_Click()
Dim TopRow As Integer
TopRow = Selection.Row
Dim Height As Integer
Height = Selection.Rows.Count
Dim BottomRow As Integer
BottomRow = TopRow + Height - 1
Range("C" & BottomRow).Formula = "=sum(A" & TopRow & ":A" & BottomRow & ")
/ $F$1"
End Sub

The only unusual thing I've done is to ignore part of the current selection.
I get the top row's number, plus the number of rows in the selection,
allowing me to determine the bottom row. I then force the summed range to
be in column A and the put the formula in column C. This means that you
don't actually have to select the correct column before hitting the button -
just make sure that the right rows are in the selection.

Share: 

 

This Question has 6 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Conditional Summing Or get search suggestion and latest updates.


Tagged: