Read value on Sheet1 from Sheet2 using vlookup - excel

I have the following on Sheet1:
Then on Sheet2, I have data. Following is the image.
I want to read the today's and tomorrow's for all the fruits from Sheet2 to Sheet1
I tried vlookup, but it didn't give me a right answer. It was confusing. I also tried to incorporate an if statement with the vlookup, but that made it more confusing.

If you data is consistent, you can use this formula =IF(C$2="Today",INDEX(Sheet2!$D$3:$D$800,MATCH($B3,Sheet2!$B$3:$B$800,0)),INDEX(Sheet2!$D$3:$D$800,MATCH($B3,Sheet2!$B$3:$B$800,0)+1)) in cell C3. drag formula below whole table...

Maybe there is way to match with blank cells in between, but the best practice is to fill out those blanks to save your time and make the formula clean, moreover, it is very easy with this trick:
First, highlight the column (ie. B1 to B6), and then go Home > Editing > Find & Select > Go To Special > Blanks > OK, =, upper arrow key, Ctrl + Enter. This way it will fill out all the blanks with the most available text in it.
Then you can perform this easy formula to do the subtotal task:
=SUMIFS($I$3:$I$13,$G$3:$G$13,$B3,$H$3:$H$13,C$2)
Please note that I put everything in the same tab to show you how this is being done. You should change those ranges accordingly based on your data setup. This way, you can have more data and different criteria be added on and still get the correct answer as I have shown you in the above screenshot.

Related

Excel - How to fix letter

I have a column B with numbers and I want my row 2 to be 1-B3, 1-B4, 1-B5 and so forth.
If I type in =1-B3 and extend it to the right it becomes 1-C3, 1-D3 and so forth.
If I type in =1=$B3 and extend it to the right it just stays 1-B3.
How do I lock the letter B so that only the number will increase when I extent it to the right?
Yeah. So you can't do that in a single, manual copy or range extension.
You could (as JvdV suggested) write a more complex formula, that will transpose on copy/extend. But I'm not sure if that's what you're trying to learn.
You could also write vb to automate the construction your formula. Again though, I'm pretty sure that's also not what you're asking.
Assuming you're just looking for a simple manual solution to what you're trying to do:
Enter the formula =1=$B3 in a cell in any EMPTY column
Doesn't matter where that cell is
Copy/extend that cell down the COLUMN to match all your column B values
Select the entire suite and Copy
Select the target starting cell, in your target row
Right Click >> Paste Special
Select Paste Formulas and Check Transpose >> Click Ok
You can now of course delete the 'temporary' column of formula

Is there a way to change the way the dragging of a function works?

I am trying to autofill cells with functions by dragging the first function I have down a lot of cells.
Currently, I have this function:
=IF(A30=A2,A2,"")
and when I drag, it becomes this:
=IF(A31=A3,A3,"")
but I want this:
=IF(A31=A2,A2,"")
I tried typing in a view previous boxes and then dragging the formula, however, then it just jumps to totally different conclusions that I don't want.
I also have a similar issue where I am copy pasting formulas, and I want it to keep the same column for one value, but not for the other:
Copied:
=IF(N7="","",B6)
Pasted Result:
=IF(P7="","",D6)
Wanted Pasted Result:
=IF(P7="","",B6)
Anything would help. Otherwise, I have to go through 40 columns by 200 rows by hand. Thanks!
You can add $ signs before the column and/or the row to achieve what you want. Your first example:
=IF(A31=A$2, A$2, "")
Try locking the row of the original A2 with a $ like A$2.
=IF(A30=A$2, A$2, "")
This is known as an absolute row, relative column. When dragged right column A will still shift to column B, column C, etc unless you lock the column as absolute as well (e.g. $A$2).

Conditional Formatting rows with shared Merged Cell

I've got a little helper spreadsheet that I use, and there are some Merged Cells.
Rather than get rid of these, which I know can cause headaches, I was looking for an idea on fixing an issue.
I have a few rows that share a merged cell. When this merged cell is not empty, I want the rows to highlight. Currently, the formula (applied over A1:B4) is =$B1<>"" and then a fill. Works okay for the first row, but not the other three:
I was thinking I could add some more logic, but there's nothing really there for me. It's a pretty simple table. Unfortunately, there's not really a way to say (for rows 2:4), if row 1 is colored, then color this row...(Although I think I've seen clever uses of Named Ranges to do something like that, but I could be mistaken).
So, in A2, what's the conditional format formula "thinking"? Is it going to =$B2<>"", in which case ...what's it looking for as B2? If I select A2, and look at the conditional format rule applied to the current selection, it still shows =$B1<>"".
Thanks for any ideas/tips. It's not a huge deal, so I don't need a VBA solution - just maybe an idea or trick for using CF with merged cells.
Edit: For a more full explanation - the idea is that col. B will have an invoice number and if it's there, make the row a color. I will be repeating this "chart" a bunch, and have some non-grouped companies, who have their own lines. I just don't like the gap of color there in my group and was trying to get it to have a color when the first of the group does.
I usually try to base my CFR's on formulas.
    
After selecting all of column A and B I created a CF rule with the following.
=AND(LEN($A1), ISNUMBER(MATCH(1E+99, $B$1:$B1)))
The approximate MATCH function simply looks for the last number in the B column. I can see a missing invoice number in a cell like B7 would generate confusion but perhaps you can expand on this for conditions not demonstrated by your examples.
If you want to use "placeholder" instead of blank cells (when there is no invoice), you could try the following formula:
=(LOOKUP(2,1/($B$1:$B1<>""),$B$1:$B1)<>"x")*LEN(A1)
With sample data it looks like this:
When the cell is left blank (no placeholder), column A is highlighted, column B is not.

Copying cells from one worksheet to another if a column matches a value

I'm trying to use formula to copy data from one worksheet to another where a column matches a certain value.
To be more specific, I want Working!A2:E100 to contain Data!A2:E100 but only for those rows where Data!C2:100 contains the value "Fixed".
Doing this with leaving blank rows is simple, I just create the formula:
=IF(Data!$C2="Fixed", Data!A2, "")
And copy that formula across all the cells.
But then I thought I'd get clever and have it not copy across blank lines, and entered a maze of unclear excel tutorials and vague error messages.
I've created this formula:
=INDEX(Data!A2:Data!A200, MATCH("Fixed", Data!$C$1:Data!$C$200, 0))
And entered it as an array formula using ctrl shift enter.
However all I get is the contents of Data!A2 repeated over and over in every cell of my spreadsheet.
Does anyone need to know what I need to do to make this work?
This is my attempt at a local prototype following the example in BruceWayne's answer, the results are visible:
As you can see "Row 2" just appears repeatedly in the result column. Excel doesn't seem to have an easy way to see what version it is any more but this seems to be a pretty recent one, it's got the ribbon with the file menu and all menu headings are capitalized.
Here's a formula you can use (note: enter this as an array):
=IFERROR(INDEX(A$1:A$200,SMALL(IF(C$1:C$200="Fixed",ROW(A$1:A$200)-ROW(A$1)+1),ROWS(A$1:A1))),"")
You may need to tweak the ranges, I think I got them to match yours, but again, probably need to tweak. You can then drag this down, and it'll fill in with the values from column A, skipping any blanks.
Edit: Here's a screenshot to (hopefully) help show what I did:
You can edit the ranges, naturally, to be over two sheets.
To clarify, A$1:A$200 is the range of what you want to return (the index). C$1:C$200 is the range that holds "Fixed".

Excel: Change multiple formulae at once?

I've sorted a chunk of data into sub-totaled fields using the Subtotal tool under the Data tab. However, you are only able to choose one formula to apply.
How can I apply a separate formula to one of the columns based on SUBTOTAL(1,RANGE)? So far I have populated it with Subtotal (9,RANGE), but is there a quicker method to select all of these and change the "9" to a "1"?
Select the column.
Press CTRL+H.
Find What: SUBTOTAL(9
Replace with: SUBTOTAL(1
Click Replace All
Assume your formulae are in the range A1:A5
Open up the VBE by hitting Alt+F11, and enter the following code in a general module of the same workbook
Function GetFormula(Cell As Range) As String
GetFormula = Cell.Formula
End Function
I have got this code from http://dmcritchie.mvps.org/excel/formula.htm
For instructions on how to insert this code in a module, see the 'Where to put the code' section at http://www.cpearson.com/excel/writingfunctionsinvba.aspx
Now, you can extract the formula. Use this formula in a helper column, say column B
=SUBSTITUTE(GetFormula(A1),"(1,","(9,")
Now copy this formula upto where you need, and copy-paste values only back where required.
You can also use this trick to modify any other formulae you need, so I suggest you keep this snippet of code handy :)
Change first or last cell then copy it
select all other cells(you can use Ctrl+Shift+up, down, left or right) then use past special and chose formulas

Resources