VBA code to sum total of like account numbers - vba

I have a code that matches 2 columns A VS C for like account numbers. If numbers match than it finds if the amounts in Column B & D match. If it does it pastes the lines of data to another spreadsheet.
I am coding a statement to find the like account numbers in column A VS C, but if the amounts don't match in column B & D than it needs to find the like account numbers in column A and sum there amounts to see if it matches the amount in column B.
How would I write the code to collect the sum of the same account numbers in column A?
If Acct = MatchAcct Then
If Amount <> MatchAmount Then
If Acct = nonmatchacct Then
(sum the values in column B for the matched account #s in column A)
The code above says if the Acct (Column A account #'s) = MatchAcct (Column C account #'s) then if Amount (Column B value) doesn't equal MatchAmount (Column D value) then the code sees if Acct (Column A account #'s) equals nonmatchacct (any other account # in Column A). If the account # matches then I want it to sum those amounts in column B.

Related

Google Sheets Query with Cell References Only Returning Headers

=query('Budget Data'!$A:$Y, "SELECT A,B, E, w Where A = '"&K1&"'AND W = "&$D$1,-1)
My Query Is looking to retrieve 4 columns from a larger dataset on "Budget Data" sheet dependent on brand name and reporting month date. I am referencing two cells for Brand Name (K1) and Date(D1). However, it is only returning the Header Row of Data. I have double checked data types and everything is matched correctly.
How can I get the rest of the data to show in this query?
Well if you are trying to date match b/w D1 and column W, then try:
=query('Budget Data'!A:Y, "SELECT A,B,E,W Where E = '"&K1&"' AND W=date '"&text(G1,"yyyy-mm-dd")&"'")
if its to match month of the date in D1 cell and relevant month data in column W, then use:
=query('Budget Data'!A:Y, "SELECT A,B,E,W Where E = '"&K1&"' AND month(W)="&month(G1)-1)

Add new column to the existing table based on specific row value conditions

For the below table sample, I want to add and additional column lets say " Amount difference" and it should have value only if the successive rows of D column has "Success" and "Waiting" as value and A B and c column value matches exactly. IN such scenario the new coulmn F (Amount difference) should have (15-0) as the value and rest of the column values should be null. If the successive rows doenst have Waiting then the value of row 2 in New column should be 15 and rest all rows should be null.
A Id
B session Id
C customer Type
D ticket status
E Amount
ORDINAL
First
A
vip
Failed
10
0
First
B
ordinary
Success
15
1
First
B
ordinary
Waiting
0
2
How can this be achieved with a query please?

Excel VBA to add unique numbers to multiple accounts

I cannot get to a satisfactory answer. I need to add comments to a data input sheet. I have added a form and I am able to populate my worksheet. However, I wish to add a unique identifier (number) to each unique customer. Row a1 has customer A; row a2 has customer B; row a3 has customer A - I would like to number the rows 1, 1, 2 respectively in column b
Assuming that you have your customers in column A and your unique numbers in column B you could use the following formula for cell B2 and then copy it down:
=IFERROR(INDEX($B$1:B1,MATCH(A2,$A$1:A1,0)),MAX($B$1:B1)+1)
Cell B1 will be set to 1 or whichever the starting number should be.
The result would be something like this:
If by "add a unique identifier (number) to each unique customer" you mean that you are trying to generate a sequence number which is unique within each unique customer, (i.e. if column A contained A, B, A, C, C then you are after 1, 1, 2, 1, 2 in column B) then you can just use the formula
=COUNTIF(A$1:A1,A1)
in cell B1 and copy it down.

Removing duplicate values from a list if it meets conditions

I have been trying to write a for each loop to go through each row in in one sheet (sheet 2) to remove duplicates in another sheet (sheet 1). I have had no luck researching either.
In sheet 1, I have a list of customer numbers in column B with the type of product they purchased in column c and the cost of that product in column d. In another sheet 2, I have a list of customers in column a and list of products in column b.
I have been trying to write a for each loop to go through each row in sheet 2 to check the customer number and product, find all the duplicates in sheet 1 with the same customer number and product, and deleting the row with the higher balance.
Sheet 1
A(Year) B(Customer #) C(Product Type) D(Cost)
1) 2015 100 A 1
2) 2015 100 A 2
Sheet 2
A(Customer #) B(Product Type)
1) 100 A
For example, if sheet 2 had 100 in column a and A in column b, it would delete row 2.
You could try using the remove duplicates option within excel, would that solve your problem? Or is Sheet 2 update to remove certain customer orders that you would also like to remove.
Edit: To expand on this. Take the list, sort it by customer and cost (low to high). Then if you click remove duplicates, you'll have the option to select what columns to use as a basis for removing duplicates, so obviously remove cost, and then it'll clear out all but the topmost row, which as now been sorted to be the lowest value.

Locate matching values in different XLS sheets and copy other cell values from matching row

Sheet1 column B contains my customer number- I need to locate this customer number in Sheet2 column F. Then copy the value from Sheet2 AE (from the row with the matching customer number) into the matching customer number row in Sheet1 column E. Note that sheet1 column B and Sheet2 column F contain the same customer numbers, but not in the same order and sorting is not an option.
So, after much trial and error I worked out the perfect solution! Thought I'd share just in case anyone else is trying to do the same.
I entered the following into column E:
=INDEX(sheet2!$AE$4:$AE$10000,MATCH(B4,sheet2!$F$4:$F$10000,FALSE)*1)