VBA/Excel: Get cell from different sheet - excel

Long story short: I have two sheets in Excel: Sheet1 which has two cells (A1 & A2) and Sheet2 (providing some data) which looks like this:
| A | B |
--|---|----|
1 | a | 5 |
2 | b | 10 |
3 | c | 15 |
4 | ...
So here's my problem: in Sheet1 when I enter "b" in A1 it should automatically enter 10 in A2.
Kinda like a simple find operation which will return the cell (or column) number and use that to return the value for the cell right next to it. But how do I do this?
Thanks in advance!

As mentioned before, a VLOOKUP is the simplest and fastest way but I assume you do not want to have a formula in that cell or on that whole Sheet1 for that matter? Here is one simple way to do the same in VBA while still using a VLOOKUP - just not on Sheet1:
Use Sheet2!Z1 for calculation, if that cell is used in your workbook, just use any other unused cell in an area that is hidded for example.
Formula in Sheet2!Z1 :
=VLOOKUP(Sheet1!$A$1,Sheet2!$A$B,2,FALSE)
Simple VBA to populate Sheet1!A2:
sum DoIt
Worksheets("Sheet1").Range("A2").Value = Worksheets("Sheet2").Range("Z1").Value
end sub
You can call the DoIt sub with a button for example and it will keep your Sheet1 / cell A2 clean of formulas.

Related

Is there a way in Excel to extract rows by column string value?

Can someone help me with excel? I want to extract data by OU name to different sheets. I'm aware of using filters or using a text-to-column function, but for filters, it's just manual work which would love to automate, and for the text-to-column function it does not work as some of the rows have more parameters than others. Please see per example:
Sheet 1 (Main)
Name | dn
A1 | CN=A1,OU=int,OU=Region1, DC=company,DC=com
A2 | CN=A2,OU=Ext,OU=AddiotionalInfo, OU=Region1,DC=company,DC=com
B1 | CN=B1,OU=int,OU=Region2,DC=company,DC=com
B2 | CN=B2,OU=ext, OU=Region3,DC=company,DC=com
C3 | CN=C3,OU=ext, OU=Region2,DC=company,DC=com
Is it possible to extract data to:
Sheet 2 by OU=Region1
Name | dn
A1 | CN=A1,OU=int,OU=Region1, DC=company,DC=com
A2 | CN=A2,OU=Ext,OU=AddiotionalInfo,OU=Region1,DC=company,DC=com
Sheet 3 by OU=Region2
Name | dn
B1 | CN=B1,OU=int,OU=Region2,DC=company,DC=com
C3 | CN=C3,OU=ext,OU=Region2,DC=company,DC=com
Sheet 4 by OU=Region3
Name | dn
B2 | CN=B2,OU=ext,OU=Region3,DC=company,DC=com
There are more regions to it so maybe there’s a formula in which it would be possible to enter “RegionX” and extract it to the second sheet?
I’m pretty new to excel and how to extract data so any resources would also be helpful. A lot of information provided on google regards the extraction of data by numbers, not by values.
Thank you!
If you have Excel 365 you can use this formula:
=FILTER('Sheet 1'!A2:B6,ISNUMBER(FIND("OU=" & A1,'Sheet 1'!B2:B6)))
It assumes that the data are on Sheet 1 and the region to be filtered for in A1 of the target sheet.

Generate List of Data from different sheets in excel

Here's the thing, I want to display a list of data from different sheets in excel file
Ex:
Sheet 1:
| A | B
--|---------------|--------------
1 | Payee: | Pedro
2 | Check Number: | 15263
3 | Date: | 12/05/2016
Sheet 2:
| A | B
--|---------------|--------------
1 | Payee: | Juan
2 | Check Number: | 15685
3 | Date: | 12/06/2016
and So on
Then in final sheet Display :
CheckNumber
15263
15685
I tried different formulas like VLOOKUP, INDIRECT, still I can't find answers.
Copy paste is not an option because I want it to be dynamic
Hope you guys Help
Assupmtions:
1. Name of the sheets of your workbook are Sheet1, Sheet2, Sheet3, and so on....
2. Check Number is always in Cell B2 of all sheets.
Enter the following formula in the second row of the column you want to list down Check Number and copy/drag it down(say Column B).
=INDIRECT("Sheet"&ROW()-1&"!"&"$B$2")
This will give you following output:
Actually i find a code here :https://msdn.microsoft.com/en-us/library/cc793964.aspx
i tried it and it works, though i use VBA because i cant find a formula for it

Excel: Select every 5th column on another sheet, drag and autofill

I'm looking to select every 5th column from another sheet, and put it into one row where they're next to each other, and be able to drag it so it autofills as there is a lot more columns.
It should come out like:
=Sheet1!B$4 | =Sheet1!G$4 | =Sheet1!L$4 | =Sheet1!Q$4 ...
=Sheet1!C$4 | =Sheet1!H$4 | =Sheet1!M$4 | =Sheet1!R$4 ...
...
How can I do this with a formula?
In your first cell of choice:
=INDEX(Sheet1!$4:$4,5*(COLUMNS($A:A)-1)+ROWS($1:2))
Copy across and down as required.
Note that INDEX set-ups should be preferred to volatile OFFSET/INDIRECT ones.
Regards

Excel Function Help - Compare 2 Cells in Worksheet to 2 Cells in another worksheet, if they match, return value from a different column

I'm wondering if someone would be able to offer some advice on the best way to do this please:
Data in Worksheet # 1
Col A | Col B | Col C
Part-1 | 8 | 2
Part-2 | 7 | 7
Part-7 | 9 | 4
Part-8 | 2 | 6
Data in Worksheet # 2
Col A | Col B | Col C
Part-1 | 8 | *Return value* (If Part-1 is found and 8 matches, return 2)
Part-2 | 7 | *Return value*
Part-3 | 8 | *Return value*
In Worksheet#2 in Cell C2 - I would like to check if the Part-1 in A1 is found in Col A in Worksheet#1. If it is, then I would also like to make sure the Number is B2 in Worksheet#2 matches the Qty in Col B next to the same part#, if both the Part# and Qty match, then i would like to copy across the value from the corresponding cell in Col C in Worksheet#1, to Col C in Worksheet#2. If it does not match, I would like it to return a 0.
Here is the a variation on Reinier's second approach in a form that will work in any version of Excel. You can use references to the specific data ranges, as I have done here, or to entire columns.
=SUM((A2=Sheet1!$A$2:$A$5)*(Sheet2!B2=Sheet1!$B$2:$B$5)*Sheet1!$C$2:$C$5)
This is an array formula, so it needs to be entered with the Control-Shift-Enter combination. It performs the same operation as the SUMPRODUCT. (There are several other ways to do this, such as using MATCH with INDEX or OFFSET.)
Essentially, what you are doing is a lookup based on values in two columns. Looking at it from that angle, you can use a the SUMPRODUCT function, which is supported in any version of Excel. Enter the following in Sheet2, cell C2:
=SUMPRODUCT((Sheet1!$A:$A=$A2)*(Sheet1!$B:$B=$B2)*Sheet1!$C:$C)
Select and drag down the right-bottom corner of C2 to complete column C.
This only works by virtue of the fact that the values in Sheet1, column C, are numbers. It breaks if value pairs in column A and B of Sheet1 occur multiple times, but you did not address that situation in your question in the first place.
For versions 2007 and up, you can use the more convenient function SUMIFS with basically the same approach:
=SUMIFS(Sheet1!$C:$C,Sheet1!$A:$A,$A1,Sheet1!$B:$B,$B1)
Alternatively, you can use a combination of IF and VLOOKUP functions. A formula that will work for Excel 2007 or newer is the following:
=IFERROR(IF(VLOOKUP($A1,Sheet1!$A:$C,2,FALSE)=$B1,VLOOKUP($A1,Sheet1!$A:$C,3,FALSE),0),0)
Older versions of Excel do not support IFERROR, but you can still use a similar approach as explained here.
I have uploaded an example workbook here, which includes an alternative method in column D of Sheet2 as well.

Cell Value pickup from different sheet

I have 5 sheets in a workbook namely Sheet1, Sheet2, Sheet3.... Maintaining some data in each sheet. In first sheet namely Consolidation I need the B3 Cell value of each sheet to be displayed in each cell
Table in the Consolidation sheet will be as below
SheetNo| Name | value (Value of B3 Cell of respective sheet )
| |
1 | Party 1 | Value of Sheet1!B3
2 | Party 2 | Value of Sheet2!B3
3 | Party 3 | Value of Sheet3!B3
4 | Party 4 | Value of Sheet4!B3
:
:
N | Party N | Value of Sheetn!B3
:
:
:
Z | Party Z | Value of SheetZ!B3
I want this to be done most likely through some cell functions only not using VBA Scripting
go to your Consolidation sheet:
a1: 1, a2: 2, a3: 3 etc
a2: ="Party "&a1
a3: =INDIRECT("Sheet"&a1&"!b3")
auto fill rest
Unless I'm missing something haven't you sort of already answered it with your example?
=SheetName!Address will return the value of Address on SheetName
If you wanted it a little more dynamic so you dont have to manually fill the sheet name, you could do something like this.
=INDIRECT("Sheet" & Row() & "!$B$3")
However it will only do numeric sheet names. (unless N and Z are just numbers then theres no problem)
Just looked and saw that you've got the sheet number next in Column A so you can substitue Row() for $A$1
To refer to a cell by name, you can use the INDIRECT() function, as in:
=INDIRECT("'"&$B1&"'!$B$3")
Here, B1 is the cell containing the name of your sheet. The expression inside the parentheses will evaluate to, for example, 'Party 1'!$B$3. INDIRECT() will expand that to the actual value of cell B3 in sheet Party 1.
The extra single-quotes are required to deal with the spaces in your sheet names.

Resources