I'm trying to solve a rather basic question in a excel sheet using vba but I can't find the answer...
I am working on a timetable which is dynamically populated from an other excel sheet with boolean values True or False.
The named range is called "A" in excel and contains boolean values True or False. Every column represents a possible start hour. Every row represents a different collage with a starting hour and an end hour. Each row can have NO values (entire row = False = collage is on leave)
OR the row can have two values TRUE on different cells in the same row representing start hour and end hour.
What I would like to achieve is a to find ROW by ROW for a couple of boolean TRUE. If found the cells between the first and second True should be colored in let's say yelow.
I am able to loop in a named range finding a specific value but I'm unable to find a pair of TRUE values in a specific row. As a double check I want to be sure that the first an second TRUE MUST be on the same row. So it is impossible to color between 2 cells in a different row.
See picture :
Some advice or thought would be greatly appreciated!
You can do this with conditional formatting.
Select the full range and then use the formulas below in conditional formatting.
=COUNTIF($A1:A1,"TRUE")>1 formatted as white
=COUNTIF($B1:B1,"TRUE")>0 formatted as yellow
The formulas count the the number of cells with "True" for the specified range.
Another way could be to add 2 columns to the right of your data and use formulas to find the start and finish times and then conditionally format based on the time headings and the 2 new values.
Related
I have an excel spreadsheet that I need to find out if there are duplicate values for 3 of the cells within the range. Basically I need to see if the Last Name, First Name and Address cells in one row match any other row exactly and then push it out to another range so I can use it as a report of duplicate values. I've seen tons of tutorials on finding matches and using conditional formatting but not to match 3 cells, just one. Is there a way to do this without VBA?
=MATCH(1,(LastName_Value=LastName_SearchRange)*(FirstName_Value=FirstName_SearchRange)*(Address_Value=Address_SearchRange),0)
It looks for a Match of 1 in the given conditions row by row. If a condition = TRUE it returns 1, if FALSE 2.
If one of the conditions is FALSE it will result in 0 (*0=0). If all 3 conditions are TRUE it returns a 1 (1*1*1=1). This formula returns the row number if found.
I have an Excel Spreadsheet with some sample values in a column:
E00BC1
171700
8201C0
C003A0
I want to add a new column and set the value of each row in that column based on the above data. If the cell in the existing column starts with "E0" I want a value of "RA", if "17" a value of "SB", if "82" a value of "SA" and if the cell in the existing column starts with "C0" a value of "RB" in the new column.
I found this example:
=IF(ISNUMBER(SEARCH(G4,"E0")), "RA")
and I made it work once, for one cell but I did something to break it. I also can't figure out how to nest the above to test for each of the 4 above conditions. Excel keeps telling me that the formula has too many arguments.
You can use CHOOSE with MATCH:
=CHOOSE(MATCH(LEFT(A1,2),{"E0","17","82","C0"},0),"RA","SB","SA","RB")
It's a little long, but one way to do it is with multiple IF() statements, using LEFT([cell],2):
=IF(LEFT(A1,2)="E0","RA"&A1,IF(LEFT(A1,2)="17","SB"&A1,IF(LEFT(A1,2)="82","SA"&A1,IF(LEFT(A1,2)="C0","RB"&A1,""))))
I am trying to populate B2:D5 with "yes"/"No" ( Figure 1) based on the criteria that if I find the respective pvalue( Column A) , in the 'Test' column in a separate sheet and the Fvalue matches the column header of figure 1. I tried using the formula visible in figure 3. However, it incorrectly labels the cow and chicken columns. Which I suspect is due to it stopping at the first " True" value it finds, and not iterating over the other values once it finds said true value.
Use COUNTIFS()
In B2:
=IF(COUNTIFS(Sheet1!A:A,$A2,Shee1!B:B,B$1),"Yes","No")
Then copy over and down the grid.
Where Sheet1 is the list.
After doing a long search, I have yet to find an answer. I feel like I am asking something so out of the ordinary, like "How do you count unicorns?"
So here it goes:
How do you in Excel... count the number of TRUE cells in a FILTERED "named range"?
I found one that will work with specifying the Column - Row Index like A2:A100.
=SUMPRODUCT(SUBTOTAL(3,OFFSET(A2:A100,ROW(A2:A100)-MIN(ROW(A2:A100)),,1)), --(A2:A100=TRUE))
That doesn't work for me. Got to be Named Ranges. I can't use a helper column either. I'd rather not use VBA. And... there is one more request for some additional magical powers: My named range is the whole column, headers and all. works with SUBTOTAL anyway.
What version of Excel are you using? In 2013, I am able to make this work properly.
I populated A2:A100 with 50 TRUE and 49 FALSE values and B2:B100 with 99 RAND() values. I then filtered on various number filters in column B and all of the below formulas worked properly, counting only the visible TRUE values in column A.
Example 1: Original Formula
=SUMPRODUCT(SUBTOTAL(3,OFFSET(A2:A100,ROW(A2:A100)-MIN(ROW(A2:A100)),,1)), --(A2:A100=TRUE))
Example 2: Non-Dynamic Exact Named Range
Range named "NonDynamic" and set to:
=Sheet1!$A$2:$A$100
Formula:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(NonDynamic,ROW(NonDynamic)-MIN(ROW(NonDynamic)),,1)), --(NonDynamic=TRUE))
Example 3: Dynamic Named Range
Range named "Dynamic" and set to:
=OFFSET(Sheet1!$A$1,1,0,COUNTA(Sheet1!$A:$A)-1)
Formula:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(Dynamic,ROW(Dynamic)-MIN(ROW(Dynamic)),,1)), --(Dynamic=TRUE))
Note: is a dynamic named range an option for you? They are often significantly more efficient than referencing an entire column, especially if there are no blank values in the column between the first and last row of data.
Example 4: Non-Dynamic Named Range of Entire Column
Range named "WholeColumn" and set to:
=Sheet1!$A:$A
Formula:
=SUMPRODUCT(SUBTOTAL(3,OFFSET(WholeColumn,ROW(WholeColumn)-MIN(ROW(WholeColumn)),,1)), --(WholeColumn=TRUE))
All four examples produce the exact same results in Excel 2013. For example, I filtered on column B > 0.5; this left 26 TRUE values visible of 50 total. All four formulas changed from 50 to 26.
What is the best way to find cells whose formulas refer to blank cells in Excel VBA. I'd like to delete any cell that references a blank cell.
More concretely, I have a two sheets: One sheet contains the actual values:
Product Month1 Month2 Month3
Sample1 1 3 5
Sample2 5 7 6
Sample3 3 8 2
The other is a summary view, with formulas to sum up the values, with the following formulas:
Product Month1
=values!A2 =SUM(values!B2:D2)
=values!A3 =SUM(values!B3:D3)
=values!A4 =SUM(values!B4:D4)
=values!A5 =SUM(values!B5:D5)
TOTAL =SUM(values!B:D)
Now in the previous example, the last raw refers to a blank row, namely the fifth row. Excel will show those cells as "0". Is there a mechanism to delete those cells within VBA?
Please note I prefer deleting the rows, to keep the TOTAL row close to the actual last value. Otherwise, the Total row might be distant from the rest of the values. Also, having blank cells with formulas may lead to a large Excel file.
EDIT: Clarified the question to role out the keeping the cells blank.
Is it always the last row, that could evaluate to 0?
If so u Could use a IF statement like:
=IF(SUM(values!B2:D2) > 0 ,values!A2,"") =IF(SUM(values!B2:D2),SUM(values!B2:D2),"")
No VBA needed...
I think Autofilter is the way to go here. If there's a zero in column A, I'm guessing you want to hide that whole row. You say delete, but I wonder if hide is a better way.
Put a filter on the range and for column A select everything except 0.
You could do this without having to write code to delete rows. I would use a variant of Arnoldiuss' solution.
For the Month total use:
=IF(LEN(values!A2)>0,SUM(B2:D2),"")
In this way, you can simply fill-down all the formulas and not have to worry if you reference a non-existent product.
Based on your edit i guess a pivot table fits your needs.
Add the products to the rowlabels and add the following calculated field to the values
=SUM(Month1,Month2,Month3)
Then add a value filter > 0
I would not recommend deleting rows in the "formula worksheet", for future use the series would wrecked, because of the missing references.