Sum all values if zip code matches county (3 different tables)

davilillo

New Member
Joined
Jan 9, 2019
Messages
14
Hello everyone,

My name is David and I've been following the forum for a while. I've learned a lot but never got to write a post, so here I go!

I'm trying to calculate the California Sales Tax that I have to remit to the state by county (aargh!), and have 3 tables:

1. Zip code and tax collected per order
2. Zip code and county it's located at
3. Total sales tax collected per county

The top of the table looks like this:

olpeWKq

BvMsIBL.png



What I'm trying to do is match the zip code of each order (first 2 columns) with their respective county (middle 2 columns), and then add them all up to reflect the total sales tax collected per county (last 2 columns). I've been at it for a while but can't figure it out. Thanks a lot beforehand for your help!
 
Are your Zip codes either all text or all numbers?
Looking at your image col A is left aligned, whereas col D is centred.
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Zip codes are all numbers. I manually centered column D, but forgot to do the same with column A. Also, the Number format in all of them is General.
 
Upvote 0
When you debug what line is highlighted?
 
Upvote 0
This is what I got with some test data


Excel 2013/2016
ABCDEFGH
1PostcodeAltitudePostcodeCountyCountyTotal
2900042.5190002BedfordshireBedfordshire132.17
3900053.690001BedfordshireBerkshire180.12
4900045.390005BedfordshireBristol
59001180.1290004BedfordshireBuckinghamshire258.1
69000217.290011Berkshire
79001313.190010Buckinghamshire
89001110090012Buckinghamshire
99001210190013Buckinghamshire
10900047.56
119000579
129000217
139001273
149001371
Input


Looking at the image in post#1, in an empty cell put
=a2=d4
and in another
=e4=g20
what do they say?
 
Upvote 0
@davilillo
Please do not quote whole posts (when they are large) as it just clutters up the thread. Post#16 is fine as the quote is small.
should the values in A2 & D4, be the same?
If so they aren't, hence the problems.
 
Last edited:
Upvote 0
Sorry about that. How come it is showing FALSE, if both numbers are the same? Perhaps as a result of different formats?
 
Upvote 0
They aren't the same, check for leading/trailing spaces.
Also try
=ISTEXT(A2)
=ISTEXT(D4)
 
Upvote 0
This could be because you have Total in column A and the Vlookup will not find it. This will skip any unfound zips from column A instead of giving an error.

Try

Code:
Sub totaltax()
Dim flr As Long
Dim slr As Long
Dim tlr As Long
flr = Cells(Rows.Count, "A").End(xlUp).Row
slr = Cells(Rows.Count, "D").End(xlUp).Row
tlr = Cells(Rows.Count, "G").End(xlUp).Row
For y = 2 To tlr
    taxcol = 0
    For x = 2 To flr
        If UCase(Cells(x, "A")) <> "TOTAL" Then
        On Error Resume Next
            If Application.VLookup(Cells(x, "A"), Range("D2:E" & slr), 2, 0) = Cells(y, "G") And UCase(Cells(x, "A")) <> "TOLTAL" Then taxcol = taxcol + Cells(x, "B")
        End If
    Next x
    Cells(y, "H") = taxcol
Next y
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top