Add separate values in a Column

S

Sue

Hi All

I found the following in this forum and adapted it to my needs however I
have a problem - this is a membership annual payment subscription column and
there are
6 different values e.g £30, £15, £13, £10, £5, and Free and those values
could be in any cell in the column is it possible to add them up separately
and place the total values in different text boxes on the userform - Tb6 =
£30 Total Tb5 = £15 Total etc


Private Sub Add1_Click()
Dim ws As Worksheet
Set ws = Worksheets("Members")
Set r = Range("P3:p401")
Count = 0
For Each rr In r
Count = Count + rr.Value
Next
Tb1.Value = Count


End Sub
 
D

Dave Peterson

You can use a formula in a worksheet like:

=countif(P3:p401,30)
to count the cells that contain 30.

In your code you could use this to count the cells.

sometextbox.value _
= application.countif(worksheets("sheet9999").range("P3:p401"), 30)

You could multiply this result by 30 to get the total value

or

you could use:
=sumif(p3:p401,30)
in code:
sometextbox.value _
= application.sumif(worksheets("sheet9999").range("P3:p401"), 30)
 
S

Sue

Hi Dave

Thanks for the all the help -- used the CountIf in code and it worked super
-- got rid of all those different colums for £30 & £15 etc -- all in one now
and can add and multiply values and manipulate them any way I want
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top