VBA Loop Statements Excel, Matching, Counting - vba

I've never written an excel VBA statement before and would like some guidance.
I have a workbook with multiple sheets open. I'm trying to match data on sheet 5 with data on sheet one and count the sum of all values that match.
Sheet 5 looks like this:
Company Name Matches
Company A 57
Company B 31
Company C 20
Company D 10
Sheet 1 looks like this:
Company Name Dollar Amount
Company A 45000
Company B 50000
Company A 60000
Company A 62000
Company D 70000
Sheet 1 is several hundred lines long.
Basically, I need to count the aggregate dollar amount in Sheet 1 for all instances where the company name in sheet 1 matches the company name in sheet five.
I tried a countif and countifs statements in excel. I did not receive the result I needed. I think I need to use a do until loop to calculate what I need. Unfortunately, I have no experience in this area (my expertise is law).I'm sort of stuck knowing where I need to go but not sure how to get there.
I'd appreciate any help. Thank you for your time.

Assuming that your Aggregate Dollar Amount ("Total") is on column B in "Sheet 1" then on B2 you would place the formula:
=SUMIF(Sheet5!A:A,Sheet1!A2,Sheet5!B:B)
This will add all Dollar Amounts on "Sheet 5" if the corresponding values on Column A is equal to A2 (ie "Company A"). You can then drag down it will reference the appropriate company name. Regards,

Related

Use of Index and Match function with Count/Counta/Countif to count the results on a 3rd wookbok

I have great success in guidance from the experts on Stack. I need guidance once more. :)
I have workbook 1 that has a copy of names on column A and email addresses on column B. Workbook 2 that has copy of names on A and email addresses on column B and data that I need copied on Column c on workbook 2.
I have a workbook 3 in which I would like to use to build a table with matched and counted from the formula I need. Below I will show.
workbook 1 pic:
Workbook 2 pic:
Workbook 3 pic:
Ultimately, I wanted the index,matched and counted total to show up on the basic table shown on workbook 3. As you can see there are 4 email addresses that match between work book 1 and workbook 2, but there are also 4 email addresses that do not match. after the matching and unmatching is found, i want the formula to give me the count of the matched and unmatched from column c in workbook 2.
so if you just use your eyes and count, you will see that rows 2 through 4 these email addresses matched between work book 1 and work book 2. that would give me a total of 2 drinks expenses and 2 food expenses from the matching found, but also give me 2 tickets expenses and 2 parking expenses from the unmatched found.
For the Matched:
=SUMPRODUCT((COUNTIFS('Sheet1'!A:A,'Sheet2'!$A$2:$A$100,'Sheet1'!B:B,'Sheet2'!$B$2:$B$100)>0)*('Sheet2'!$C$2:$C$100=$B3))
For the unMatched
=SUMPRODUCT((COUNTIFS('Sheet1'!A:A,'Sheet2'!$A$2:$A$100,'Sheet1'!B:B,'Sheet2'!$B$2:$B$100)=0)*('Sheet2'!$C$2:$C$100=$B7))
These are untested as I did not want to retype that much data, but in thoery should work.

Excel vba code to copy names found in multiple worksheets and count how many times they appear

I need some help writing some VBA code.
Basically I have one spreadsheet with 4 worksheets (CLIENT1, CLIENT2, CLIENT3, CLIENT4)
Each worksheet contains a column called CONTACT.
This CONTACT column contains a person name
The CONTACT column can be in a different position in each worksheet ie the CONTACT column in CLIENT1 is in Column D whereas it appears in column E in CLIENT2
I would like some help writing some code that will create a new Worksheet called SUMMARY.
The SUMMARY worksheet would contain in Column A a list of all the names found in the CONTACT column and in Column B it would count the number of times that persons name was found.
So the SUMMARY worksheet would end up looking something like this.
A B
1 John Smith 4
2 Brad Black 2
3 Gary Soth 1
4 Bob Brown 6
5 Sam Drow 2
Hope this makes sense and thanks for your help
Andy
Note : I am just playing with Excel and not using VBA but think you can achieve it without using VBA also.
You can use COUNTIF and solve your problem.
I will show you step by step. I cant attach excel here so adding images. If you wish to have excel which i prepared then just give me your email, I will send it.
This is summary which I got by using the formula (you can see that highlighted :
Client Name column can get value from the sheet where you can combine all your unique client names and use that as base.
Check Client1, 2, 3 & 4 sheets.
Hope this may help you.
Just found that in Excel you can use the Remove Duplicates function to remove all unwanted names. I can then use the count function across all 4 worksheets to get the required information.
Thanks
Andy

vlookup if name is matched display employee id

Ive never used vlookups i have a spreedsheet not sure if this is the right function. I have two sheets
Sheet 1
first name last name username
Sheet 2
first name last name employee id business unit
I need in column D on sheet 1 to have employee id ive below. Pay no attention to column letters and sheets because i moved to another sheet to try getting this right.
=MATCH(B11,Sheet1!C:C,0)
Any help is much appreciated.
So you realize you have to match both first and last names? There are several ways to accomplish this depending on how many employees you have in sheet 2: a) small list could a two-column search using array formula; b) large list just create another column in both sheets joining last & first names and do a MATCH or VLOOKUP on them.
Since your needs are simple and to illustrate option (b):
Insert a column in both Sheet1 and Sheet2 after the "last name"; you should now have an empty column C in both sheets.
Assuming you have column headers in row one, and thus data starts in row two, set cell C2 in both sheets with function =B2&","&A2, then fill-down that formula on both sheets in all rows.
Set Sheet1 cell E2 to formula =VLOOKUP(Sheet1!C2, Sheet2!$C:$D, 2, False), and fill-down that formula in all rows.
Voila, employee IDs on Sheet1. I do have to say this is so Excel 101. There are all sorts of examples and tutorials on this easily found using even the most trivial Google searches.

LibreOffice populating cells

I have a spreadsheet containing data identifying the depot where a product is stored, the supplier of the product and the manufacturer of said product.
I wish to break this one spreadsheet into four .csv files and import csv files into an already created PostgreSQL db. Typically, depot.csv, product.csv, supplier.csv and manufacturer.csv.
depot.csv has <15 entries, supplier.csv & manufacturer.csv <350 entries each and product.csv < 2,000 entries.
Example of what I want to do.
I have created a list of unique depots in a worksheet called depot.
id name
paris
berlin
london
original spreadsheet data
id Depot depot_id PRODUCT NAME product_id SUPPLIED BY Manufacturer
1 Paris 1 Hand wipes Erenco Chem Group
6 London 3 Scrub Towels Chemicraft Chem Group
7 Berlin 2 WR2 Grease Greasy Bin Chem Group
the column depot_id is populated by using the following formula
=IF(B2=depot.$B$2,depot.$A$2, IF(B2=depot.$B$3,depot.$A$3, IF(B2=depot.$B$4,depot.$A$4, 9999)))
and a worksheet called depot
Now I need a formula to populate product_id but above formula is not sufficient.
Thanks.
Tommy.
This problem is probably best solved by using the vlookup function.
Okay it's working.
Formula looks like this... in cell C2 enter the following
=VLOOKUP(D2,Product.$A$2:$B4586,2,0)
explanation:
D2 = the text being searched for
Product.$A$2:$B$4586 = the search array, in another worksheet, being searched
2, = the value to be posted in cell C2. This is from the column B in the search array. The leftmost column should be the column containing the value searched for.
0 = signifies a unsorted/unordered list.
See http://forum.openoffice.org/en/forum/viewtopic.php?t=46746 for better explanation.
Also http://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_VLOOKUP_function
Thanks to Mauritz for reinforcing my research.
Tommy.

Using excel VBA to lookup cell value, and return multiple values based on that cell

Sorry for the terrible title, I didn't know how to summarise my problem.
I have a worksheet with a bunch of payments. Each payment is made to an ID number. I have another worksheet with the ID numbers and their breakdown; the percentage of the payment that should be allocated to each pot.
e.g
Client XYZ ,100 payment in worksheet one, has ID 123.
worksheet 2 has,
123 | A | 5%
23 | B | 95% and so on
I would like to be able to produce a third worksheet of the form.
XYZ, 123, A, $5
XYZ, 123, B, $95
So each payment is multiplied by its breakdown and displayed on another sheet along with the rest of the clients info in the adjoining columns.
Even just a start on this would be very helpful. Many thanks.
From reading your question it seems you just want to perform a simple lookup.
If you don't need to use VBA, you can do this easily using excel's VLOOKUP function.