Flag Data in Excel Programatially - sql

I have two sheets in an excel workbook. One of the sheets has 8 ID numbers. The other sheet has about 5000 rows, not every row matches one of the ID numbers on the other sheet. I want to flag the rows where an ID number is an exact match to the other sheet and extract them to a separate sheet.
At the moment I was thinking I could just type in
=IF(A2=sheet2!b3,1,0) OR IF(A2=sheet2!b4,2,0) OR IF(A2=sheet2!b5,3,0) OR IF(A2=sheet2!b6,4,0) OR IF(A2=sheet2!b7,5,0) OR IF(A2=sheet2!b8,6,0) OR IF(A2=sheet2!b9,7,0) OR IF(A2=sheet2!b10,8,0)
Then copy and paste them to a separate sheet, but this doesn't work for some reason.
Any help would be much appreciated.

I didn't fix your formula for all the 8 ID's, but you should be able to add additional checks.
=IF(A2=$B$3;1; IF(A2=$B$4;2; IF(A2=$B$5;3;0)))
This basically reads as:
compare A2 with B3, if they match return 1 (note the use of $ sign in order to always use the B3 cell, this is called absolute cell reference)
if it doesn't match then compare A2 with B4 and if that matches return 2
if it doesn't match then compare A2 with B5 and if that matches return 3
if it doesn't match return 0
If you wish to compare to all 8 IDs you should just nest the if's a bit more.
A simpler solution would be to use VLOOKUP.

Related

How to use INDEX and MATCH to based to cells?

I have two sheets of data in excel. I want to combine cells to bring the second cell value. Here is an example:
when I enter combining columns name and list must get value form V1 and V2.like this:
I don't have the time to type your data, so this is a rare case of a non-tested formula and may need some tweaking.
For the V1 result: (top screenshot starts in Sheet1 column A, bottom screenshot in Sheet2, column A). This formula goes into cell B2 in Sheet 2:
=Index( Sheet1!$E$2:$E$100, MATCH(Sheet2!a2,INDEX(Sheet1!$A$1:$A$100&" | "&Sheet1!$D$1:$D$100,0),0))
Adjust the first index range from column E to F for the V2 result in C2.
Copy down.
Don't use that approach with whole columns. It will be slow. Use ranges with defined rows.
Of course, if the codes in Sheet1 column A are unique, you don't need to combine them with the value in column D and can look up only the first three characters, like this for V1 (use 6 for V2)
=vlookup(Left(Sheet2!A2,3),Sheet1!$A:$F,5,0)

How to copy a row and paste it X amount of times

I simply need to copy a number of rows based on the number in a cell.
In Sheet1 I have a table and in Sheet4 I have a list of values.
I require row at A6 to be copied by and then pasted the number of times as specified in F2 in Sheet 4.
start from this (adjust where needed):
range("d4:g4").Resize(worksheets("sheet4").range("f2").value,4).FillDown

subtract the last two non-empty cell in excel

This is I think a simple problem but I can't seem to find the right solution for it. I don't know if VBA is needed for it. Basically I just want to subtract the last two non-empty cell in Excel. Example: I have the cell A1 and cell B1 and then subtract the value of A1 from B1 and place this value at the same row but another column C1 and so on. I have read this to get the last non-empty cell but I need two non-empty cell and perform operation on them.
=LOOKUP(2,1/(A:A<>""),A:A)
Is there an easier way to do this? Or should I use VBA?
EDIT:
the reason is I'm making a somewhat similar to a balance sheet but a simple one, the user will just enter deposited value at the first column and expenses at the second column and then display the balance in the third column.. and vice versa.
EDIT:
Sample
Put this in C4 and copy down:
=SUM($A$3:$A4)-SUM($B$3:$B4)
If you want to copy the formula past the data so it will automatically fill when data is inserted you can do what #Dirk stated:
=IF(A4&B4<>"",SUM(A$3:A4)-SUM(B$3:B4),"")
Put it in C4 and copy down as far as desired.
This way you can fill the column with the formula and as the data is filled it will change from the empty string to the running total.
EDIT:
Regular formula:
=IF(ROW($C1)=1,OFFSET($C1,0,-2)-OFFSET($C1,0,-1),OFFSET($C1,-1,0)+OFFSET($C1,0,-2)-OFFSET($C1,0,-1))
in cell C3 put "=A3-B3" in cell C4 put "=C3+A4-B4" then copy down.
This will start the balance at 3000 in C3 then add any deposits or minus any withdrawals to the rest of column C.

How to Auto Fill Cells in Excel based on a dependent drop down list?

I have 2 sheets in sheet1 is the master sheet where all data are stored
In sheet2 I want to link the data of sheet1 in sheet2 in different cells
In Sheet1 I have 'Name' 'Mobile' 'Address' 'Pin' in A1 B1 C1 D1
In Sheet2 A2 I did data validation of the name of the persons which is stored in Sheet1, now I want that when I will select the respect list automatically the Mobile Address Pin of the person will auto fill in B2 C2 D2
& for that I am using the following formula
=VLOOKUP($A2,Sheet1!$A:B,COLUMNS(Sheet1!$A:B),0)
If a person having 3 mobile numbers stored in my Sheet1, I want to place those 3 mobile numbers in my Sheet2 Mobile column, How do I do that ??
Column A is the main dependent, But if there are blank rows then Data validation doesn't work, how can I do that ??
or any macro required ??
This is a tricky one. You will need to have a unique identifier in your records somewhere because a VLOOK and a MATCH formula will only pull back the first record it finds.
I would suggest looking into this link, it tells you how to do this. I have done it before, but it takes some practice no doubt so be warned.
Excel to the Next Level by Mastering Multiple Occurrences

How to compare a list of rows to another list of rows in Excel?

I am trying to figure out if there are any differences between a list of data with another. In order for a row of data to "match" with another row, the row must have the same values in their corresponding column. The rows themselves do not have to be in any particular order. In particular, I am dealing with a parts list, where there are part numbers, descriptions, etc. I am trying to figure out if any rows of data are different from rows of data from another list.
I found Compare two sheets using arrays, which may have the answer to my problem, but I am having trouble figuring out how to adapt to my code due to inexperience in Visual Basic.
I was able to get it to work for a single column of data, comparing one column of data from one sheet to another, but cannot get it to compare entire rows of data.
Here is an example of I want this to work:
Sheet 1 Sheet 2
Column 1 Column 2 Column 1 Column 2
Row 1 22a 33 11 11
Row 2 22a 33a 22a 33
Row 3 55 22b 55 23b
The code in the link will tell you what is not in sheet 1 but in sheet 2 and vice versa. In this example, I would like the code to tell me Sheet 1 Row 2 and Sheet 1 Row 3 are not in Sheet 2, and Sheet 2 Row 1 and Sheet 2 Row 3 are not in Sheet 1 (Sheet 1 Row 1 and Sheet 2 Row 2 match).
If that is ok by you, you can do it without VBA using the following formula:
={IF(IFERROR(MATCH(A1&"|"&B1;Sheet7!$A$1:$A$3&"|"&Sheet7!$B$1:$B$3;0);-1)=-1;"Unique";"")}
Assuming that each of your tables start in A1 (so that the tables with three entries span A1:B3), and entering this formula into C1 (and copying it down), press CTRL+SHIFT+ENTER when entering the formula to create an array formula, this will show the word "Unique" in column C if the pair in that row on that sheet is not in any of the row-pairs on sheet 2.
You can then use conditional formatting to highlight unique rows, filter on the tables to include only unique rows, or some other way of doing what you need.
NOTE 1: I have entered my numbers in Sheet6 and Sheet7 instead of 1 and 2. The formula written above goes into Sheet6.
NOTE 2: My language use ; instead of , as function separator, so if yours use , you need to change that.
NOTE 3: You will need to expand the ranges Sheet7!$A$1:$A$3 and Sheet7!$B$1:$B$3 if your set grows (this will happen automatically if new rows are inserted in between the old ones). The best is still probably to create named ranges for each of the 4 columns, exchange the references with those, and manage the named ranges instead of the formulas.
NOTE 4: If your data set contains the character "|", you need to change that as well, to match some character that you for sure do not have there.
Alternatively you could in column C on each cheet enter (assuming first entry in C1)
=A1&"|"&B1"
and copy this down, then run the solution from your copied example using that C column instead of on A1 and B1.