excel vba use command if - vba

I have two excel files (file 1 with sheet 1 and file 2 with sheet 2).
Both have inside, in column A all the names (for example in A1: "a", in A2: "b" etc etc), in column B the values of relative lenghts (for example in B1: "2", in B2: "3" etc etc) but the orders of the things in the two sheets are different; so, I would want to say: "if the name in a cell in column A of sheet 1 is the same of the name in a cell in column A of sheet 2, so compare the relative values in column B and write TRUE in column C of one of the sheet (if the values are identical) or FALSE"
for you is possible? could you help me, please?
thanks in advance

If Sheet1 has
a 5
b 6
c 7
d 8
and Sheet2 has
c 3
d 8
a 5
then you can type
=IFERROR(IF(B1=INDIRECT("Sheet2!B"&MATCH(A1,Sheet2!A$1:A$4,0)),"Match Found",""),"")
into cell C1 of Sheet1 and drag the fill handle down and you will get
Match Found
Match Found
in column C of Sheet1. No VBA needed. :)
Note: Since your second sheet is actually in a separate file, you'll want to change Sheet2 to [file2.xlsx]Sheet1 in cell C1.

If you want to avoid INDIRECT function then try the following:
Assuming your Sheet1 of file1 is as follows:
And Sheet2 of another file is like:
Enter the following formula in Cell C1 of `Sheet2' and drag/copy it down as required.
=IFERROR(IF(B1=INDEX([file1.xlsx]Sheet1!$B$1:$B$5,MATCH(A1,[file1.xlsx]Sheet1!$A$1:$A$5,0)),TRUE),FALSE)

I would want to copy the word TRUE, only if I compare the same cell of the two sheets and I find that only a part of the name of that cell is the same ( because in reality in cell there is not only a, b, c but a sentence for example as "Sample 1 SX arrow" and others as "Sample 1 DX arrow") and so I want to put in column C the word TRUE only if not complete name in column A are the same but only part of the sentence ( for ecample only the part "SX arrow"!!!
How can I add this in the loop ?

Related

look for Column heading and sum up

I have been working with a excel file with a lot of data, which is arranged in 2 sheets.
I would like to get data from sheet 1 to sheet 2 with reference to the column headings.
For example:
So if I want to find the sum of function 1 person A with criteria 1, the command have to go and find the heading "sum of function 1" in sheet 1 and choose the data that are only under criteria 1 and sum it up in sheet 2 cell D5. (By using column heading reference instead of cell reference).
The table range is A2 : U80.
Thanks.
First you have to format your data as table (select the data -> Menu Insert -> Table). Then you rename your table, for example Table1. Let's say one of the columns you want to sum on the sheet2 is called ColumnName.
On the sheet 2 you write a formula
=SUM(Table1[ColumnName])
The result will be what you are after.
You should try it by SUMIFS(). Syntax will be
=SUMIFS(AgeRange from sheet1,NameRange Sheet1, Name cell Sheet2, PlaceRangeSh1, Place Cell Sh2)
Tell me if requires further help.

Compare two columns then add another if the data is the same

I have two separate worksheets that I would like to search in and then populate a column if two columns represent the same data. I'm having a hard time explaining this so please have patience.
I have worksheet1 with column "A" having text and numbers in it. In the same sheet column "B" has the data that I want to show in worksheet2 if Both Column "A" match in both worksheets.
Example:
Worksheet1
Column A
Text text text (2012-R-0000)
blah blah blah
text text text (2012-R-0001)
Column B
20-204
20-405
40-609
Worksheet2
Column A
2012-R-0000
2012-R-0001
Column E
(empty) I would like the data in Worksheet1 Column B to be placed here.
Thank you in advance for any assistance with my question.
Assuming your worksheet 1 and worksheet 2 datas starts with A1
use the below formula at worksheet 2 in E1
=VLOOKUP("*"&A1&"*",Sheet3!A:B,2,FALSE)
French Formula:
=RECHERCHEV("*"&A1&"*";Sheet3!A:B;2;FALSE)
and drag down
Proof of Work
Use VLookUp in Worksheet 2 like this.
In cell E1 of Worksheet 2 write the following:
=VLOOKUP(A1;Worksheet1!$A$1:$B$30;2;FALSE)
Then simply drag the formula down. It will match the first column from both worksheets, then paste the corresponding data from column B in worksheet1 to column E in worksheet 2. You'll have to edit "Worksheet1" to match the name of the acctual worksheet, and the number 30 to match the number of rows in worksheet 1.

how to create a column that only gets the matching value from another sheet in EXCEL

i would like to create an extra column in sheet one which displays a character (for example G) after it finds the matching values from sheet 2.below are two screen shots i have taken for all your conveniences.
please note,in sheet 1 i have marked two rows with identical bs_cd 6374 which matches the bs_cd 6374 in sheet 2 also.what i want is to have a character G in sheet 1 under column G.
thanks in advance
Insert into the cell G2 this formula and drag it down:
=IF(VLOOKUP(B2;Sheet2!$A$2:$A$100;1;FALSE)=0;"";"G")
Change $A$2:$A$100 to your range in sheet2

Using VBA in Excel to create a macro to fetch data between worksheets

I have two sets of data that need to be collated, the first has a list of questions (workbook 1), the second Workbook where those same questions are spread out over 5 sheets with ID numbers associated with them. I need a macro that will take a value from workbook 1, search for it in the entire workbook 2 and then locate its ID value and then copy this value into the first workbook.
I've tried numerous codes but I can't get anything near working, the closest I came was using a index, match function but that only does one column, whereas i need approximately 15 columns (I.e the whole worksheet)
Any help would be great!
I'm assuming your Excel workbooks are structured something like the following (based on your description).
Workbook 1
Sheet 1
A1 "What is the answer to life and all its questions?"
A2 "Who is the creator of Linux?"
A3 "What is your favorite text editor?"
Workbook 2
Sheet 1
A1 "What is the answer to life and all its questions?" B1 103401
A2 "Who is the creator of Linux" B2 104113
Sheet 2
A1 "What is your favorite text editor" B1 101031
We can take the index values from column B of workbook 2 (corresponding to our questions in column A of workbook 1) and copy these to column B of workbook 1. I'll provide a solution of how you could easily do this with cell formulas.
Workbook 1
Sheet 1
A1 "What is ..." B1 =Index([workbook2.xlsx]Sheet1!$B$1:$B$100$,
Match(A1, [workbook2.xlsx]Sheet1!$A$1:$A$100,0))
A2 "Who is ..." B2 =Index([workbook2.xlsx]Sheet1!$B$1:$B$100$,
Match(A2, [workbook2.xlsx]Sheet1!A$1:$A$100,0))
...
You could do the same thing in column C for Sheet 2 of workbook 2
Workbook 1
Sheet 1
A1 "What is ..." C1 =Index([workbook2.xlsx]Sheet2!$B$1:$B$100$,
Match(A1, [workbook2.xlsx]Sheet2!$A$1:$A$100,0))
A2 "Who is ..." C2 =Index([workbook2.xlsx]Sheet2!$B$1:$B$100$,
Match(A2, [workbook2.xlsx]Sheet2!A$1:$A$100,0))
...
Then one of the columns B-E would contain the ID number and the rest of the columns would contain N/A. Note that I only search the first 100 rows of the first 5 sheets of workbook 2.

Hyperlink to a cell on another sheet in Excel

I am working on Excel report in which I need to pass a link which can take me to a cell referenced.
In below example, I have two sheets on same workbook. Now if I click on cell "A1" on Sheet:1, then it should take me to cell "E1" on Sheet:2.
I know by paste special I can pass hyperlink, but tricky part is data on Sheet:2 is dynamic so I can't go that route.
After looking on Google, I have found out multiple things, so I clubbed them together but it is throwing error "Reference is not valid".
Here is the formula that I've used on cell "A1" on Sheet:1:
=HYPERLINK("[Sample.xlsx]Sheet:2!(ADDRESS(MATCH(""ABC"",BEFORE,0),MATCH(""ABC"",BEFORE,0),1))","ABC")
Here BEFORE is a name range that covers A1 to E1.
Sheet:1
a b c d e
1. abc
Sheet:2
a b c d e
1. x x x x abc
Appreciate your inputs.
=HYPERLINK("[Sample.xlsx]'Sheet2'!" & ADDRESS(1,MATCH("abc",BEFORE,0)),"ABC")
If your sheet name might have spaces then make sure to add the single quotes around the name.