Hide lines with zero values - excel

I have the following table generated by a pivot:
╔════════╦══╦══════════╦════════════╦═════════╦═════════╦═════════╦═════════╦═════════╗
║ Line # ║ ║ Car ║ Sold/Stock ║ Store 1 ║ Store 2 ║ Store 3 ║ Store 4 ║ Store 5 ║
╠════════╬══╬══════════╬════════════╬═════════╬═════════╬═════════╬═════════╬═════════╣
║ 1 ║ ║ BMW ║ Sold ║ 5 ║ 1 ║ 0 ║ 6 ║ 4 ║
║ 2 ║ ║ BMW ║ Stock ║ 2 ║ 0 ║ 2 ║ 3 ║ 4 ║
║ 3 ║ ║ Audi ║ Sold ║ 3 ║ 4 ║ 5 ║ 5 ║ 8 ║
║ 4 ║ ║ Audi ║ Stock ║ 3 ║ 1 ║ 0 ║ 0 ║ 1 ║
║ 5 ║ ║ Mercedes ║ Sold ║ 2 ║ 0 ║ 4 ║ 5 ║ 6 ║
║ 6 ║ ║ Mercedes ║ Stock ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║
╚════════╩══╩══════════╩════════════╩═════════╩═════════╩═════════╩═════════╩═════════╝
I want to hide the last row(6). Can it be done? I can't filter columns store 1 2 3 because i only want to filter when they all are blank.
Thanks

The filters for the pivot table should show you all available values including "blank". Set the drop-down to show multiple values, and turn that one off.

You can do this in VBA, like so:
Dim hideMe as Bool
hideMe = True
For Each c In Range("E7:I7")
If c.Value <> 0 Then
hideMe = False
End If
Next
Rows(7).EntireRow.Hidden = hideMe
The script assumes that you will want to hide the row (hideMe = True), and only decides otherwise if there is any cell in that range which is different from 0.

Related

Insert one table into another table, when column header names are not in the same order

I want to insert all the data from one table copy_tbl at the end of another table paste_tbl both in different worksheets, but in the same workbook.
The columns that have the same header name will not be in the same order in both tables, so I need to rearrange the order of the inserted data columns to match the destination.
The copy_tbl might have column header names that doesn't exist in paste_tbl, and I want those columns to be added to paste_tbl (this is optional and the columns that doesn't have a match in the destination table can be ignored, if it's a headache to do).
I've been trying to read up on ListObjects and also trying to code some kind of loop that matches column header names before inserting data, but I'm stuck.
This seems like a fairly simple task, and I was certain I would at least figure it out with the help of google, but I've been sitting here for 6 hours now and I'm not getting anywhere.
I did find a solution to this by using Power Query, but I'm on a Mac, and it hasn't been implemented in Excel for Mac yet :|
Is there someone willing to help me solve this problem?
Thanks in advance!
Edit:
I abandoned trying to use ListObjects and tried something else.
This is the code I've come up with so far:
Dim r As Range, c As Range, msg As String
Application.ScreenUpdating = False
With Sheets("copy_sht").Range("1:1").CurrentRegion
For Each r In Sheets("paste_sht").Range("1:1")
Set c = .Rows(1).Find(r.Value, , , xlWhole, , 0)
If Not c Is Nothing Then
.Columns(c.Column).copy
r.PasteSpecial xlPasteValues
Else
msg = msg & vbLf & r.Value
End If
Next
Application.CutCopyMode = False
Application.ScreenUpdating = True
End With
End Sub
This replaces some of the values into the correct cells, and it also overwrites the whole first column with data from the second table.
This is what I want to happen:
╔════════════╦═══════╦═══════╦═══════╦═══════╗
║ Number ║ info1 ║ info2 ║ info3 ║ info4 ║
╠════════════╬═══════╬═══════╬═══════╬═══════╣
║ 1 ║ abc ║ ║ xyz ║ 456 ║
║ 2 ║ ║ 123 ║ ║ ║
║ 3 ║ ║ ║ 456 ║ ║
║ 4 ║ ║ ║ ║ ║
║ 5 ║ abc ║ asd ║ zxc ║ ║
╚════════════╩═══════╩═══════╩═══════╩═══════╝
╔════════════╦═══════╦═══════╦═══════╦═══════╗
║ Number ║ info1 ║ info3 ║ info4 ║ info5 ║
╠════════════╬═══════╬═══════╬═══════╬═══════╣
║ 1 ║ def ║ www ║ 123 ║ a ║
║ 3 ║ ║ ║ ║ b ║
║ 5 ║ ║ ║ ║ c ║
║ 6 ║ ║ ║ ║ d ║
║ 7 ║ 123 ║ ║ ║ e ║
╚════════════╩═══════╩═══════╩═══════╩═══════╝
╔════════════╦════════╦═══════╦════════╦════════╦═══════╗
║ Number ║ info1 ║ info2 ║ info3 ║ info4 ║ info5 ║
╠════════════╬════════╬═══════╬════════╬════════╬═══════╣
║ 1 ║ abcdef ║ ║ xyzwww ║ 456123 ║ a ║
║ 2 ║ ║ 123 ║ ║ ║ ║
║ 3 ║ ║ ║ 456 ║ ║ b ║
║ 4 ║ ║ ║ ║ ║ ║
║ 5 ║ abc ║ asd ║ zxc ║ ║ c ║
║ 6 ║ ║ ║ ║ ║ d ║
║ 7 ║ 123 ║ ║ ║ ║ e ║
╚════════════╩════════╩═══════╩════════╩════════╩═══════╝
The first table paste_tbl will become the third table after the data has been added from the second table copy_tbl.
This is what the code actually does with the first table:
╔═════════╦═══════╦═══════╦═══════╦═══════╗
║ Number ║ info1 ║ info2 ║ info3 ║ info4 ║
╠═════════╬═══════╬═══════╬═══════╬═══════╣
║ 1 ║ def ║ ║ www ║ 123 ║
║ 3 ║ ║ 123 ║ ║ ║
║ 5 ║ ║ ║ ║ ║
║ 6 ║ ║ ║ ║ ║
║ 7 ║ 123 ║ asd ║ ║ ║
╚═════════╩═══════╩═══════╩═══════╩═══════╝
So what I'm still missing is:
Adding missing columns from copy_tbl to paste_tbl.
Making sure the data that is pasted from copy_tbl is matched with the same unique ID located in the first column in paste_tbl, and if that unique ID doesn't exist, instead paste the whole row at the bottom of the table.
If data already exists in a destination cell, I want to concatenate that with the data from copy_tbl.
Edit 2:
Realizing some parts of VBA I've never understand, I tried to do this the old fashioned way with formulas, and I succeeded.
It's probably not very optimized, because it takes a while to populate the table, and I was getting tired when I finished it. But it gets it done.
Sorry if it's a bit messy, but what it does is it populates a new table basen on the values of two other tables tabell1and tabell2. It merges any existing cells data with the same unique ID $A2 which needs to be in the first column of all tables.
You have to collect all the unique ID's and place them without duplicates in the table that is to be populated. Then just paste the following formula into the first row of every column of your table.
=IFERROR(
IF(
IF(
COUNTIF(tabell1;$A2)=1;
VLOOKUP($A2;tabell1;MATCH(B$1;tabell1[#Headers];0);FALSE);""
)
=
IF(
COUNTIF(tabell2;$A2)=1;
VLOOKUP($A2;tabell2;MATCH(B$1;tabell2[#Headers];0);FALSE);""
);
IF(
AND(COUNTIF(tabell1;$A2)=1;COUNTIF(tabell2;$A2)=1);
IFERROR(
VLOOKUP($A2;tabell1;MATCH(B$1;tabell1[#Headers];0);FALSE);
VLOOKUP($A2;tabell2;MATCH(B$1;tabell2[#Headers];0);FALSE));
CONCATENATE(VLOOKUP($A2;tabell1;MATCH(B$1;tabell1[#Headers];0);FALSE);" ";VLOOKUP($A2;tabell2;MATCH(B$1;tabell2[#Headers];0);FALSE)));
IF(
COUNTIF(tabell2;$A2)=1;
VLOOKUP($A2;tabell2;MATCH(B$1;tabell2[#Headers];0);FALSE);VLOOKUP($A2;tabell1;MATCH(B$1;tabell1[#Headers];0);FALSE)
));" ")

How can I search for an item within a cell that's also in a range?

I have Table A:
╔═══╦═════╦═════════════╦══════════════════╗
║ ║ a ║ b ║ c ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 1 ║ ID ║ LIST VALUES ║ Table B Values ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 2 ║ 123 ║ 231,583 ║ eggs,bacon ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 3 ║ 789 ║ 518,732 ║ bacon,bread ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 4 ║ 101 ║ 55,38 ║ tomato,onion ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 5 ║ 213 ║ 894,231 ║ ham,eggs ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 6 ║ 141 ║ 55,38,894 ║ tomato,onion,ham ║
╠═══╬═════╬═════════════╬══════════════════╣
║ 7 ║ 516 ║ 548,43 ║ milk,butter ║
╚═══╩═════╩═════════════╩══════════════════╝
And I have Table B:
╔═══╦═════╦═════════════╗
║ ║ a ║ b ║
╠═══╬═════╬═════════════╣
║ 1 ║ ID ║ LIST VALUES ║
╠═══╬═════╬═════════════╣
║ 2 ║ 231 ║ eggs ║
╠═══╬═════╬═════════════╣
║ 3 ║ 518 ║ bacon ║
╠═══╬═════╬═════════════╣
║ 4 ║ 732 ║ bread ║
╠═══╬═════╬═════════════╣
║ 5 ║ 55 ║ tomato ║
╠═══╬═════╬═════════════╣
║ 6 ║ 38 ║ onion ║
╠═══╬═════╬═════════════╣
║ 7 ║ 894 ║ ham ║
╠═══╬═════╬═════════════╣
║ 8 ║ 548 ║ milk ║
╠═══╬═════╬═════════════╣
║ 9 ║ 43 ║ butter ║
╚═══╩═════╩═════════════╝
These are representations of the data I have, and what I need help with. The actual data is a lot longer than these tables, and the delimited items can be very long.
What I'm trying to do is populate Table A, Column C. I need to search the items from TABLE B, Column A for the listed items in TABLE A, Column B within the cell through the whole range.
I guess this can be done vice versa as well. I am familiar with INDEX-MATCH function, but I'm not sure how to add searching within the cell.
Use TEXTJOIN and ISNUMBER/SEARCH:
=TEXTJOIN(",",TRUE,IF(ISNUMBER(SEARCH(","&$G$2:$G$9&",",","&B2&",")),$H$2:$H$9,""))
If you have Windows Excel, try:
C2: =TEXTJOIN(",",TRUE,VLOOKUP(FILTERXML("<t><s>"&SUBSTITUTE(B2,",","</s><s>")&"</s></t>","//s"),$G$2:$H$9,2,FALSE))
Table A
Table B
Results

Sumproduct subtract total amount from oldest month in different month columns

I hv 4 different columns of Database
╔════╦════════════╦═════════╦═════════════╦═════════════╗
║ ║ A ║ B ║ C ║ D ║
╠════╬════════════╬═════════╬═════════════╬═════════════╣
║ 1 ║ Date ║ Party ║ Debit ║ Credit ║
║ 2 ║ 25-12-2019 ║ John ║ 50,000 ║ ║
║ 3 ║ 27-12-2019 ║ Neil ║ 50,000 ║ ║
║ 4 ║ 29-12-2019 ║ John ║ 1,00,000 ║ ║
║ 5 ║ 01-Jan ║ Neil ║ 50,000 ║ ║
║ 6 ║ 05-Jan ║ John ║ 8,00,000 ║ ║
║ 7 ║ 08-Jan ║ John ║ 70,000 ║ ║
║ 8 ║ 28-Jan ║ Neil ║ 20,000 ║ ║
║ 9 ║ 02-Feb ║ John ║ 30,000 ║ ║
║ 10 ║ 15-Feb ║ Neil ║ 19,000 ║ ║
║ 11 ║ 27-Feb ║ John ║ 21,000 ║ ║
║ 12 ║ 04-Mar ║ John ║ 22,000 ║ ║
║ 13 ║ 08-Mar ║ Neil ║ 88,000 ║ ║
║ 14 ║ 09-Mar ║ John ║ 6,00,000 ║ ║
║ 15 ║ 05-Apr ║ John ║ 7,05,000 ║ ║
║ 16 ║ 21-Apr ║ Rebbika ║ 25,00,000 ║ ║
║ 17 ║ 05-May ║ John ║ ║ 7,00,000 ║
║ 18 ║ 07-May ║ Neil ║ ║ 5,00,000 ║
║ 19 ║ 19-May ║ John ║ ║ 1,00,000 ║
║ 20 ║ 21-May ║ Rebbika ║ ║ 10,00,000 ║
╚════╩════════════╩═════════╩═════════════╩═════════════╝
and here is the result table (Which actually is a Trial of each Party with monthly remaining balance
╔═══╦═════════╦════════╦════════╦═══════╦════════╦═════════╗
║ ║ E ║ F ║ G ║ H ║ I ║ J ║
╠═══╬═════════╬════════╬════════╬═══════╬════════╬═════════╣
║ 1 ║ Party ║ Dec-19 ║ Jan-20 ║ Feb-20║ Mar-20 ║ Apr-20 ║
║ 2 ║ John ║ - ║ 220000 ║ 51000 ║ 622000 ║ 705000 ║
║ 3 ║ Neil ║ 10000 ║ 70000 ║ 19000 ║ 88000 ║ 0 ║
║ 4 ║ Rebbika ║ - ║ - ║ - ║ - ║ 1500000 ║
╚═══╩═════════╩════════╩════════╩═══════╩════════╩═════════╝
and this is the Formula i am using in E2 to J4.
The formula i copied is from Cell I2
=IF(SUMPRODUCT(--(MONTH($A$2:$A$20)=12)+--(MONTH($A$2:$A$20)<=2),--($B$2:$B$20=F3),$C$2:$C$20)-SUMIF($B$2:$B$20,F3,$D$2:$D$20)>1,SUMPRODUCT(--(MONTH($A$2:$A$20)=3),--($B$2:$B$20=F3),$C$2:$C$20),IF(SUMPRODUCT(--(MONTH($A$2:$A$20)=3),--($B$2:$B$20=F3),$C$2:$C$20)-(SUMIF($B$2:$B$20,F3,$D$2:$D$20)-SUMPRODUCT(--(MONTH($A$2:$A$20)=12)+--(MONTH($A$2:$A$20)<=2),--($B$2:$B$20=F3),$C$2:$C$20))<1,"",SUMPRODUCT(--(MONTH($A$2:$A$20)=3),--($B$2:$B$20=F3),$C$2:$C$20)-(SUMIF($B$2:$B$20,F3,$D$2:$D$20)-SUMPRODUCT(--(MONTH($A$2:$A$20)=12)+--(MONTH($A$2:$A$20)<=2),--($B$2:$B$20=F3),$C$2:$C$20))))
E.g:-
Total Due Payment of Dec to John is 150,000
Payment received has nothing to do with month or date, its just the whole payment we have received till the date
So, If he has paid us 120,000
Balance of Dec=30,000, and Jan-Feb-Marc... Due payment is still pending as it is
If we have Received the Total Payment 1,021,000
Then it will clear the 150,000 of Dec and 870,000 of Jan, and 1,000 from the Feb and will Show Dec Column as Nill, Jan=Nill, Feb 50,000
Total of Received Amount should be subtracted from the oldest month of billing
But the function i am using is really messy and making sheet a bit heavy, Is there any possible shorter and nice way to perform this task without using vba codes but with shorter formula than the one i am trying. its MS 2007
Any help will be appreciated
I finally Got it
=IFERROR(1/(1/ROUND(MAX(0,SUMIFS($C:$C,$B:$B,$E2,$A:$A,"<="&EOMONTH(F$1,0))-SUMIF($B:$B,$E2,$D:$D)-SUM($E2:E2)),0)),"-")
Dragging it vertically and horizontally worked perfectly fine.

Looking for keywords within column of longer phrases

If a keyword on Sheet 1 is contained within a cell in a column on Sheet 2, I want to copy the value in another column in Sheet 2. How can I do this? I have tried VLookUp and other but without success as they only work when the keyword exactly matches the target cell.
Sheet 1
╔═══╦═══════════╦══════════╗
║ ║ A ║ B ║
╠═══╬═══════════╬══════════╣
║ 1 ║ Horse ║ Winnings ║
║ 2 ║ Shadowfax ║ ║ < should show $9000
║ 3 ║ Telefax ║ ║ < should show $0
║ 4 ║ Ceefax ║ ║ < should show $660
╚═══╩═══════════╩══════════╝
Sheet 2
╔═══╦══════════════════════════════════╦══════════╗
║ ║ A ║ B ║
╠═══╬══════════════════════════════════╬══════════╣
║ 1 ║ Race ║ Winnings ║
║ 2 ║ Ascot, Ed, 2014-06-10 ║ $50 ║
║ 3 ║ Goodwood, Shergar, 2016-05-11 ║ $80 ║
║ 4 ║ Doncaster, Shadowfax, 2015-06-30 ║ $9000 ║
║ 5 ║ Goodwood, Ceefax, 2016-07-21 ║ $660 ║
╚═══╩══════════════════════════════════╩══════════╝
You can use wildcards (the * character) in Excel formula string comparison.
Try a basic Index-Match:
In Sheet 1 B2:
=Index('Sheet 2'!B:B, Match("*" & A2 & "*", 'Sheet 2'!A:A, 0))
Or SumIfs to add up what's in 'Sheet 2'!B:B if there's more than one value per input on Sheet 1.
=SumIfs('Sheet 2'!B:B, `Sheet 2`!A:A, "*" & A2 & "*" )

Find a max value for each Range interval in Excel

I have data in an Excel sheet that depict the quantity of various gases present at depth say d. So for each depth interval like from 3238.1 to 3238.9 i need to find the max value of all the gases columns (C1-C3, IC4,IC5,nC5, OC2).
For example for depth 3238 there are 9 interval (3238.1 to 3238.9) so i need to find the max value in all the gas columns like for column C1 max value for 3238 will be 5650.
Sometimes there are more than 10 intervals for a meter e.g 1338.1, 1338.2, ...up to 1338.15 etc or sometimes less than 10, e.g, 1338.1,1338.3,1338.5,1338.6 etc because of missing data.
INPUT:
╔═══════╦════════╦══════╦═════╦═════╦═════╦═════╦═════╦═════╦══════╗
║ ║ Depth ║ C1 ║ C2 ║ C3 ║ iC4 ║ nC4 ║ iC5 ║ nC5 ║ OC2 ║
╠═══════╬════════╬══════╬═════╬═════╬═════╬═════╬═════╬═════╬══════╣
║ ║ 3238.1 ║ 0 ║ 125 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1200 ║
║ ║ 3238.2 ║ 5601 ║ 78 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1600 ║
║ ║ 3238.3 ║ 5610 ║ 156 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1588 ║
║ ║ 3238.4 ║ 5612 ║ 120 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1900 ║
║ ║ 3238.5 ║ 5640 ║ 300 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 2100 ║
║ ║ 3238.6 ║ 5650 ║ 401 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 2648 ║
║ ║ 3238.7 ║ 5601 ║ 366 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 2841 ║
║ ║ 3238.8 ║ 5610 ║ 102 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 450 ║
║ ║ 3238.9 ║ 5612 ║ 211 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1800 ║
║ ║ 3239.0 ║ 111 ║ 20 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1723 ║
║ ║ 3239.1 ║ 121 ║ 39 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1646 ║
║ ║ 3239.2 ║ 56 ║ 12 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1569 ║
║ ║ 3239.3 ║ 214 ║ 6 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1492 ║
║ ║ 3239.4 ║ 125 ║ 9 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1415 ║
║ ║ 3239.5 ║ 300 ║ 7 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1338 ║
║ ║ 3239.6 ║ 390 ║ 14 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 3160 ║
║ ║ 3239.7 ║ 312 ║ 16 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1523 ║
║ ║ 3239.8 ║ 360 ║ 18 ║ 3 ║ 0 ║ 0 ║ 0 ║ 0 ║ 1634 ║
║ ║ 3239.9 ║ 380 ║ 19 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 4823 ║
║ ║ 3240.0 ║ 80 ║ 6 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 3065 ║
╚═══════╩════════╩══════╩═════╩═════╩═════╩═════╩═════╩═════╩══════╝
Example OUTPUT:
╔═══════╦══════╦═════╦════╦═════╦═════╦═════╦═════╦══════╗
║ Depth ║ C1 ║ C2 ║ C3 ║ iC4 ║ nC4 ║ iC5 ║ nC5 ║ OC2 ║
╠═══════╬══════╬═════╬════╬═════╬═════╬═════╬═════╬══════╣
║ 3238 ║ 5650 ║ 401 ║ 0 ║ 0 ║ 0 ║ 0 ║ 0 ║ 2841 ║
║ 3239 ║ 390 ║ 39 ║ 3 ║ 0 ║ 0 ║ 0 ║ 0 ║ 4823 ║
╚═══════╩══════╩═════╩════╩═════╩═════╩═════╩═════╩══════╝
The data shows the quantity of various gases present at depth d.
I need to find the maximum for each meter interval (max for 3238.1 to 3238.9).
I tried using the Excel max function but was not able to achieve the desired output.
What is the best way to achieve this, which functions should I use or macros etc.
You may use array formula max(if()) to calculate max value over the range, matching criteria and floor() function to get rid of the decimal part:
=FLOOR(A2,1)
=MAX(IF(FLOOR($A$2:$A$21,1)=K2,$B$2:$B$21))

Resources