Return values under a column if the value in anther column does not equal to zero - vba

So what I need to do is basically to return the values in column E to column I if the values under column G is non-zero. I was able to return all the non-zero values under column G to column K, but I not sure if I could retrieve the corresponding values under column E and F to I and J.
Is this something that could be done by a formula, or I have to use VBA?
Appreciate any insights! I've attached the sample here:

If you are not worried about duplicated items on column G, you should be able to use a combination of INDEX() and MATCH():
=INDEX(E$1:E$7,MATCH($K1,$G$1:$G$7,0))
If you have issues with duplicate values use the following array formula (Press Ctrl+Shift+Enter after editing the formula).
For Cell I1 use the following (drag it to cells J1 and K1):
=+INDEX(E$1:E$8,MATCH(TRUE,INDIRECT("g"&1+1):$G$8>0,0))
And for the rest, copy the following formula on cell I2 and drag it down and to the right:
=+INDEX(E$1:E$8,MATCH(TRUE,INDIRECT("g"&MATCH(I1,E$1:E$8)+1):$G$8>0,0)+MATCH(I1,E$1:E$8))

Related

Sum of Named Ranges to Array in Excel

I have values 1,2,3 and 2,3,4 in columes A and B respectively. I want column C to be 1+2, 2+3, 3+4. I have named the first 3 cells of column A as RANGE_A and the first 3 cells of column B as RANGE_B
I have tried sum(RANGE_A, RANGE_B), but that gives me the actual total of 15 in every cell of the output range.
I don't want to do this in VBA, and it would be cleaner if I can use the ranges like I have tried, but if all else fails i'll be just using A1+B1,A2+B2 etc..
***** EDIT ********************************
Where you want to sum two named ranges ={sum(RANGE_A, RANGE_B)} produces a scalar value, reflected in every cell of the output array, equal to the sum of both columns.
My solution is in fact, incredibly simple (thanks to QHarr, who got this right even when my original question was wrongly written!)
={RANGE_A + RANGE_B} produces an output array where each value is the sum of each pair of cells in each range. That's all i was looking for!
Cheers
J
You want to select C1:C3 and enter the following in the formula bar:
=RANGE_A*RANGE_B
then press Ctrl + Shift + Enter to enter as an array formula.
For addition you can use:
=RANGE_A+RANGE_B

VBA excel Copy Paste

Hi, I am totally new to Excel VBA. Firstly, I want to copy the data when the condition is met(copy data with reference to 144)
Secondly, compare the cells, if it is IT Operations(Table1) to IT Operations(Table2) then copy the price(money) to column F. If the variable is no there then leave blank.
This can be done with formulas. Here is one way of thinking about filling column F, with the prices for the matching items in column E, by matching the number given in the last row in E (144 Total); which i shall assume is E10 in this case.
Total formula in F1 which you then drag down is:
=IFERROR(IFERROR(VLOOKUP(E1,INDIRECT(CELL("address",OFFSET($H$1,MATCH(1*LEFT($E$10,FIND(" ",TRIM($E$10),1)-1),$G:$G,0)-1,,1,1))&":"&CELL("address",OFFSET($I$1,MATCH($E$10,$G:$G,0)-1,,1,1))),2,FALSE),VLOOKUP(E1,G:I,3,FALSE)),"")
In steps:
Extract the number of interest e.g. 144, and get rid of any trailing/leading whitespace using:
LEFT($E$10,FIND(" ",TRIM($E$10),1)-1)
Find which row this value is in as this will be the first row of the lookup range for this number. *1 converts text to a number.
MATCH(1*LEFT($E$10,FIND(" ",TRIM($E$10),1)-1),$G:$G,0)
This gives row 9.
We can use something simpler to find the last row of the range, which holds 144 Total
MATCH($E$10,$G:$G,0)
This gives row 15. So we know the data lies between rows 9 and 15 for 144.
We can turn this into a range to use in a VLOOKUP with INDIRECT and OFFSET.
=CELL("address",OFFSET($G$1,MATCH(1*LEFT($E$10,FIND(" ",TRIM($E$10),1)-1),$G:$G,0)-1,,1,1))&":"&CELL("address",OFFSET($H$1,MATCH($E$10,$G:$G,0)-1,,1,1))
This gives us $G$9:$H$15. Note adjustments of -1, to put OFFSET back in the right row, and that the OFFSET start cells are in different columns to provide the columns required for the VLOOKUP.
So we can now lookup column E values e.g. Enhancement, in our newly defined range which is accessed via INDIRECT:
=VLOOKUP(E1,INDIRECT(CELL("address",OFFSET($H$1,MATCH(1*LEFT($E$10,FIND(" ",TRIM($E$10),1)-1),$G:$G,0)-1,,1,1))&":"&CELL("address",OFFSET($I$1,MATCH($E$10,$G:$G,0)-1,,1,1))),2,FALSE)
This is saying VLOOKUP(E1,$G$9:$H$15,2,FALSE) i.e. get the price column from the range for the item specified in E1.
If this is not found i.e. returns #N/A, we can use this to first check if this is because of the merged cell that holds the 144 Total; where the value is actually in column G not H, and use an IFERROR to say, if not found in $G$9:$H$15 then try for a match using columns G:I and return column 3.
Which with pseudo formula, using priorLookup as placeholder, for the formula described in the steps above, looks like:
IFERROR(priorLookup, VLOOKUP(E1,G:I,3,FALSE))
If this still returns #N/A, we know the value is not present and we should return "". This we can handle this with another IFERROR:
IFERROR(IFERROR(priorLookup, VLOOKUP(E1,G:I,3,FALSE)),"")
So giving us the entire formula stated at the start.
Here it is used in the sheet:

using vlookup for finding matching values

I have value in A1 and another value in B1. I want to use a vlookup which checks if there is any value equal to A1 in Column A. And if These values match then B1 gets the value of the matching row of A.
As an example if A1 has a value Student and A6 has value Student. Then B1 should get the value of B6.
=VLOOKUP(
I know we use sth like this but i dont know how to fill the condition. Does anyone have any Suggestion?
=ADDRESS(MATCH(A1,C:C,0),3) where 3 is column C, you could use column(C1) here
What you are asking for cannot be done with a VLOOKUP. This is because if you are looking up a string in column A and using a reference from column A you will always return that string in column B, even if there is only one instance of that string. Unless that string did not exist in column A in the first place and then you would get an "#N/A".
The best way to solve your problem is to run a COUNTIF formula in column B, this will tell you how many instances of that string are found in column A.
Enter this into column B, and extend down:
=COUNTIF(A:A,A2)
Add a filter to column B, and filter out any 1's to give you a complete list of all your duplicates in column A.
The above formula assumes that you have headings in A1 & B1, and your data begins A2.

Searching and comparing various values using VBA

I have to create a macro which will:
Get the value from the cell A1 search this value in column C.
If the value in cell A1 exists in column C, the macro needs to be compare the value in cell B1 with values in column D.
If the value in cell A1 exists in column C AND the value in cell B1 exists in column D, then the text "Values found" should appear in cell E1.
The above needs to happen for all non empty rows in column A.
I was trying to use the following formula:
=IF(ISERROR(MATCH(A2,$C$2:$C$138,0)),"Load number not found","Load number found")
But it not working as I want. I have limited access to internet so I can't check all web sites. Would you please help me. Thanks a lot.
To check if A1 is in column C and if B1 is in column D (in the same row A1 was found in column C), then you need to do the following:
=IF(ISERROR(MATCH(A1,$C:$C,0)),"Load number not found",IF(B1=INDEX($D:$D,MATCH(A1,$C:$C,0),1),"Load number found","Load number not found"))
The first IF checks if A1 is in column C, the second IF checks if B1 is in column D (in the same row A1 was found in column C)
It will return "Load number found" only if both conditions are true. Otherwise it will return "Load number not found".
You can write a macro to do the same thing. But the easier way is to lock the cells in column E only and protect the sheet so that users will not accidentally change any of the formulas.
Update:
Since Column C can have duplicates, need to use the following array formula:
=IF(ISERROR(MATCH(1,(A1=$C:$C)*(B1=$D:$D),0)),"Load number not found","Load number found")
When you paste this formula to E1, make sure to press CTRL + Shift + Enter instead of just pressing the Enter key.
If I understand, a conventional solution with formulae is to concatenate your C and D column data and then search that. If you insert a new columnC with:
=D2&E2
copied down to suit you could apply (but say in ColumnF rather than ColumnE) your existing formula with only slight modification:
=IF(ISERROR(MATCH(A1&B1,$C$2:$C$138,0)),"Load number not found","Load number found")
subject to quite what is in which row.

Count rows that have cell don't existing in a list in Excel

Please see my image
I am have two questions:
Do you know what is the proper function to count number of rows that have F column value don't exist in range J3:J15 (expect result is 3, as the image)
List/or show values in Column A, B of above rows (the rows that have F column value don't existing)
Way №1
In cell H2 use:
=IF(ISNUMBER(MATCH(F2,$J$3:$J$15,0));"exist in list","not exist in list")
and drag it down.
Then in C12 you can use:
=COUNTIF(H2:H8;"not exist in list")
Way №2
In C12 use:
=SUMPRODUCT(1*NOT(ISNUMBER(MATCH($F$2:$F$8,$J$3:$J$15,0))))
This is an array formula, so type the formula then press CTRL+SHIFT+ENTER. Curly brackets will automatically appear at the start and end of the formula.
Then for returning list of corresponding values in column A use, say, in F12:
=IFERROR(INDEX(A:A,SMALL(IF(NOT(ISNUMBER(MATCH($F$2:$F$8,$J$3:$J$15,0))),ROW($F$2:$F$8)),ROW()-ROW($F$12)+1)),"")
this is also array formula, so press CTRL+SHIFT+ENTER to evaluate it and then drag formula down.
and in G12 for returning corresponding values from column B:
=IFERROR(INDEX(B:B,SMALL(IF(NOT(ISNUMBER(MATCH($F$2:$F$8,$J$3:$J$15,0))),ROW($F$2:$F$8)),ROW()-ROW($F$12)+1)),"")
also with array entry(CTRL+SHIFT+ENTER).