I have three columns in my Excel file that are currently being AutoFiltered. I've been tasked with setting up multiple filters. The way I began was to build a 'menu' of choices using ActiveX checkboxes and assigning the 'Linked Cell' property to a cell way out to the right. So, if the first option is checked, cell BB30 says 'TRUE'.
The issue starts with the fact that the first column has 16 items, the second column has 11 items and the 3rd column has 5. The way my boss wants it to work is if they select 2 options from column 1 and one item from column 2, it filters the data (on a separate sheet) on that information.
Example data:
Column A Column B Column C
-------- -------- --------
aCol1 bCol1 cCol1
aCol2 bCol2 cCol2
aCol3 bCol3 cCol3
aCol4 bCol4 cCol4
aCol5 bCol5 cCol5
aCol6 bCol6
aCol7 bCol7
aCol8 bCol8
etc. etc.
So, if I select aCol1, aCol2, and bCol3 -- we want to filter (ACOL1='TRUE' OR ACOL2='TRUE') AND BCOL3='TRUE' to then filter the data.
I did some searching and it seems using SELECT CASE is the way to go but this would give me more than 800 different scenarios... not to mention if nothing from a certain column is selected (only aCol1 and bCol8 selected, for example).
Is there a better way to do this?
If I have to write a separate CASE statement for each scenario, will Excel 2010 handle that many?
Finally, once I've determined what all has been selected, how do I write the VBA so that it actually DOES this?
Don't write a select block.
What you want to do is to iterate through each column and if the value is true then add an autofilter with the related value. You do this for each column and that will filter as you want to do it.
As for how to accomplish this using VBA, you can simply use the range and call the AutoFilter() method with the value to filter for. I assume you have minimal knowledge of VBA.
Range("A1:Dx").AutoFilter Field:=x, Value:=x
Related
I'm trying to create a dropdown menu in excel which eliminates values once they have been selected.
Let's assume that the dropdown offers the values 1...10. If I select 1 in the first dropdown, then the other dropdowns needs to offer only 2...10. Likewise, if I picked to, the the other should offer only 1,3,4,5,6,7,8,9,10.
Basically we want managers to rank their employees based on the performance value.
But if they rate everyone a 4, we need a ranking - but we then dont want them ranking everyone as 1.
I tried with IF statements, but we can have rankings of up to 100 people, so it was becoming a nightmare.
Not sure if I am clear?
Any help would be appreciated.
You can use data validation custom formula to avoid duplicates. It would not be a dropdown but it would work exactly as you wish:
In my example, I've selected range B2:B5 and then I applied a data validation custom formula like this:
=COUNTIFS($B$2:$B$5;B2)=1
You can even customize the error message:
With that formula, any entered value will be accepted exactly once. If it's used again, it will raise an error.
Notice I can't type a second time the value 1 because it's been already used.
You can do this by creating a helper table which lists all the valid ranks and whether or not they have been used yet. This can be on the same sheet or another, hidden sheet if you prefer:
The formula in the "Used?" column is a simply counts the number of times that rank appears in the "Rank" column and checks if it is greater than 0 - returning TRUE or FALSE:
=COUNTIFS($B$2:$B$11,$H2)>0
The "Remaining Ranks" column then uses this in a MINIFS formula to remove the used ranks:
= MINIFS(
$H$2:$H$11,
$H$2:$H$11,">"&MAX($K$1:$K1),
$I$2:$I$11,FALSE
)
This is saying to select the lowest number from the "All Ranks" column, where the rank hasn't already been listed in the "Remaining Ranks" column AND the "Used?" column is FALSE.
This will result in zeros at then bottom of the "Remaining Ranks", so we can wrap it in an if statement to replace the zeros with an empty string "":
=IF(
MINIFS($H$2:$H$11,$H$2:$H$11,">"&MAX($K$1:$K1), $I$2:$I$11,FALSE)=0,
"",
MINIFS($H$2:$H$11,$H$2:$H$11,">"&MAX($K$1:$K1),$I$2:$I$11,FALSE)
)
You can now use the "Remaining Ranks" column as your source for the data validation list, and it will update as the ranks are entered.
This will result in some blank options at the bottom of the list.
If these are an issue for you, they can be removed by using an INDEX formula in a named range. Let me know if you would like me to explain how that can be done.
I am trying to join different lists that have less than 3 values on it, there is an example
.
I was able to do it using macros, but I wanted something more automated because these lists updated quite often, is there a way of doing something like that just by using formulas? If no, is there a way of doing it using VBA but in a better way than "clicking" buttons?
Answering VBasic2008:
I am new to this intermediary/advanced excel functions. I just realized that my Macro didn't work. It does not matter where the results will be, could just be at the end of the table. I have around 20 columns.
Basically, I tried to make something that checks if the number of values in the column is below 3 and if it is it would take this list and paste on the "Group X", but I am trying to use just functions to do that, I was able to make a list with all the columns using INDEX + MOD, but it took all of the names, from AAA to the last one, and I wanted something that would take just the list with less than 3 values.
Some update:
=INDEX(IF($F$11:$J$11=3;$F$6:$J$9;"");MOD(ROW()-ROW($O$6);4)+1;INT((ROW()-ROW($O$6))/4)+1)
I was able to come up with this formula, but everything appears with some spaces.
Thanks,
Matheus
Doing this with formulas is possible, but quite advanced. Someone here will write a formula for you which you may not be able to maintain when your scenario changes.
If you already have VBA code that does what you need doing, then you can move that code to an event procedure that starts automatically when a new value is added to the columns.
The event you need is the Worksheet_Change event and it lives in the Sheet module (right-click the sheet and click "View Code". That will show the Sheet module.
In your scenario, you want to run the code when a value is changed in columns D to G, so your code must start with something like
Private Sub Worksheet_Change(ByVal Target As Range)
' run only when a value in columns D to G are changed
If Not Intersect(Target, Range("D:G")) Is Nothing Then
' your code goes here
MsgBox "You just changed a value in one of the the watched columns!"
End If
End Sub
Edit after additional requirements
If you have Office 365 with the new Dynamic Array functions, this formula approach will work.
Building on your index formula, I made a small change. You can use the modified index formula in a helper column. Then use the Filter() function on the values returned by the Index formulas.
Index formula in cell J4 and copied down to J23
=INDEX(IF($D$11:$H$11=3,$D$4:$H$7,"#"),MOD(ROW()-ROW($J$4),4)+1,INT((ROW()-ROW($J$4))/4)+1)
Filter formula in K4
=FILTER(J4:J23,(J4:J23<>"#")*(J4:J23<>0))
If I understand you correctly, try the following:
I put the formula to count the number of entries in row 2, to make it easier to add items below.
I assumed you mean three or less; and not less than three.
If you have Windows O365, you can use the following formulas: (and change the 100 to the lowest possible row)
D2: =COUNTA(D$4:D$100)
and fill right for the number of columns
I4: =FILTERXML("<t><s>" & TEXTJOIN("</s><s>",TRUE,FILTER($D$4:$G$100,$D$2:$G$2<=3)) &"</s></t>","//s")
I'm using Excel 2010 and have a datasheet with multiple tabs, this is the current SUMIF function that I am using
=IF(SUMIF('Master Data'!$J$2:$J$200,'Resource View (2)'!B22,'Master Data'!$W$2:$W$200)>0,Current_row_different column, "")
Basically, I find some rows in the other sheet that have a value of 1 I then want to use these rows that have a value of 1 but use a different column within that row to populate the true condition.
So say for instance row 4 contains a 1 at column A I then want to stay on row 4 but get the value of column B for the true condition.
Is this possible?
EDIT:
I have now managed to get the function working however its a bit of an Excel hack, because I have had to move the columns around in the master data and its a bit messy now anyway here's what I've got
=IF(SUMIF('Master Data'!$C$2:$C$200,'Resource View (2)'!B22,'Master Data'!$W$2:$W$200)>0,VLOOKUP(B22,'Master Data'!$C$2:$F$90,3,FALSE),"")
Now I know this is because VLOOKUP searches through the first column specified and it doesn't seem to work at all if i try to put the range in backwards i.e. $F$90:$C$2 instead of $C$2:$F$90. Is there any way to manipulate VLOOKUP to work like this?
Yes, actually there is a way - a brother of VLOOKUP - it's INDEX(MATCH()). It is a very useful tool, as you can look at any column and return any other, not only looking at the first one to return the ones to the right. Also, INDEX(MATCH()) can be used in forming array formulas, if you need that, while VLOOKUP cannot.
Basically, this part of your formula:
VLOOKUP(B22,'Master Data'!$C$2:$F$90,3,FALSE)
would be changed with this:
INDEX('Master Data'!$E$2:$E$90,MATCH(B22,'Master Data'!$C$2:$C$90,FALSE))
So, after all, the equivalent for
=IF(SUMIF('Master Data'!$C$2:$C$200,'Resource View (2)'!B22,'Master Data'!$W$2:$W$200)>0,VLOOKUP(B22,'Master Data'!$C$2:$F$90,3,FALSE),"")
would be
=IF(SUMIF('Master Data'!$C$2:$C$200,'Resource View (2)'!B22,'Master Data'!$W$2:$W$200)>0,INDEX('Master Data'!$E$2:$E$90,MATCH(B22,'Master Data'!$C$2:$C$90,FALSE)),"")
I have an excel sheet with 8000 records that i would like to search by postcode.
This is my client list and i would like to say search for all clients living in the "EH1","EH2","KY1","SW9" postcodes.
I would like the search to return all the values related to that postcode.
The excel document is laid out like this.
(ID,Name,Surname,Address,Postcode,Telephone Number)
Im a novice at excel spreadsheets so any help on this would be greatly appreciated.
ID Name Surname Address Postcode Telephone number
26584 John Smith 69 Bedford road Eh12 5db 0131225689
Thanks
Edited with quick and dirty method:
If you only need to use this table a few times, then there is a quick and dirty method:
Make a helper column that only includes the first 3 characters of the postcode. You do this via the left function, specifying the postcode column in the first argument, then "3" in the next, to return the first 3 characters. This effectively hides the values you haven't ticked.
You then use the filter section at the top of the column once you have made it a table as stated earlier. In the drop down menu untick "Select all", then tick the values you want to see, i.e. the postcodes you are interested in).
You can then copy the visible cells only via Copy visible cells only if you want to use just that list.
A longer, but more robust method would involve three tables. The first is your data set as it is, with the helper column as discused above included. The second would be a simple single column of all the first three letter codes you are interested in. The third would be an array function modified from this formula:
=index($a$1:$b$7,small(if($a$1:$a$7=$a$10,ROW($a$1:$a$7)),ROW(1:1)),2)
which returns multiple items based on preset criteria, ignoring those that are not specified. I would link to a site explaining this better but I am such a new user I can hardly do anything it seems :(
I suggest you simply use an autofilter on the respective column.
Here is a short tutorial for Excel 2010: AUTOFILTER TUTORIAL
I think an easy way to do this is first make Postcode column first; from Column E to Column A.
Insert a new column in Column A, then use the left function to get the first 3 characters of the postcode: =LEFT(B1,3)
With this, you can use VLOOKUP to search for the postcodes "EH1","EH2","KY1","SW9", and use multiple VLOOKUP formulas to return a column index of everything.
You'll end up with a list of everything for that specific postcode.
I have some data.
I would like to find the "unique" values in the data. That is, not any data that was duplicated.
To be clear:
A
B
C
A
B
I want
C
I do not particularly care if this makes a new column of modifies the existing column. I do not, however, want to get C highlighted - my data sets are v. large and i really don't want to be scrolling along finding hyper-color yellow entries.
(I have a sneaking suspiscion this has been asked before, but given the dual connotations of "unique", it is kind of hard to search for it here)
Its a standard option of conditional formatting
Duplicate is the default, But the box allows unique too
That menu is accessed from home tab > conditional formatting > new rule
be sure to set a format for the cell then
Conditional Formatting and Filtering is much the simplest, but if you really want a formula to obtain the unique values in a different column:
=IF(COUNTIF($A$5:$A$15,A5)=1,A5,"")
This assumes the original data is in A5:A15, and this formula is entered into another column and copied down the same number of rows. You'll end up with a load of blank cells though. You'll need to copy/paste-special values, then sort in descending order (or filter) this list so that the blanks are at the bottom and can be deleted.
Actually, slightly better would be:
=IF(COUNTIF($A$5:$A$15,A5)=1,A5,"zzz")
because, after copy/paste-special values, you can sort in ascending order and you can see the values (at the bottom) that you need to delete.