ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding values from one table to another (https://www.excelbanter.com/excel-programming/382626-adding-values-one-table-another.html)

Nimbus55

Adding values from one table to another
 
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.

merjet

Adding values from one table to another
 
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




All times are GMT +1. The time now is 01:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com