Adding values from one table to another

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This may be very simple..not sure.I need to grab three values from a table
and based on those values, create a fourth value in a second table on another
worksheet.

Eg - I have a column named Dog, one named Colour and one marked State.
So I could have a Poodle, Blue, Pregnant and I could have Spaniel, Red,
Spayed. I need to add how many of each I have and display it on a second
table...so I might have five Blue Poodles who are Pregnant...or two Red
Spaniels that are spayed ....thus the figures I want to return are 5 in the
Pregnant Blue Poodle column and 2 in the Spayed Red Spaniel column.

Any help would be appreciated - my coding skils are minimal..so be gentle.
 
Assuming your 3 columns are A-C, the following will put the count for
the particular combination in a row in column D. Revise 3rd line from
end to put said counts where you want.

Sub macro1()
Dim c As Range
Dim c2 As Range
Dim rng As Range
Dim iEnd As Integer
Dim iCt As Integer

iEnd = Sheets("Sheet1").Range("A1").End(xlDown).Row
Set rng = Sheets("Sheet1").Range("A2:A" & iEnd)
For Each c In rng
iCt = 0
For Each c2 In rng
If c = c2 And c.Offset(0, 1) = c2.Offset(0, 1) And _
c.Offset(0, 2) = c2.Offset(0, 2) Then iCt = iCt + 1
Next c2
c.Offset(0, 3) = iCt
Next c
End Sub

Hth,
Merjet
 

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

Back
Top