Filter Excel table if select cell values are true using VBA - excel

I have an Excel table with a list of multiple rating agencies in a column (Field 3, "Framework/Agency" in my book). Outside of the table, I have 5 rows, one for each agency, and a cell to the right with a drop-down menu containing only "Yes." Essentially, the only options for these five cells are "Yes" or blank. I would like to filter the table to include any agencies that are marked as "Yes" in column 2 and to exclude any agencies that are left blank. If all are blank, I would like the table to not be filtered by agency, as I have another set of macros that I am using on other columns.
An example of my other, more basic macros:
If Range("d4").Value = "" Then Range("Database").AutoFilter Field:=18
If Range("d4").Value <> "" Then .AutoFilter Field:=18, Criteria1:=Range("d4").Value
D4 is equal to another criteria that I have, and it filters field 18 in my table. My overall workbook looks something like this.
Col1 Col2
Agency 1 Yes
Agency 2
Agency 3 Yes
Agency 4
Agency 5
Col1 Col2 Col3 (column desired to be filtered Col4 Col5 Col6 (also filtered using another macro)
XXX YYY Agency 1 ZZZ AAA BBB
XXX YYY Agency 3 ZZZ AAA BBB
XXX YYY Agency 3 ZZZ AAA BBB
XXX YYY Agency 1 ZZZ AAA BBB
Given the circumstances above (A2:B7 in my book), I would like to see the results for only agencies 1 and 3, along with any other filters I have in my other filtering macros. As values change in column 2, I would like to see the results change as well.
Any help would be appreciated! Thank you in advance!

Related

find string in other column but same row vba

some cells in column D contains same numbers "123".
The macro needs to find the row of the string "xxx" in different column but same row that contains numbers "123".
This seems like a good INDEX(MATCH) use case.
If your table is something like
Col1
Col2
Col3
A
xxx
111
B
yyy
222
C
zzz
333
You can try something like
=INDEX(A2:C4,MATCH(B2,B2:B4,0),3)
Which will return 111 as you matched the row containing xxx and wanted column 3

How do we split the columns in excet sheet into two columns based on the data present in the column?

I have data in one column i.e., Purchases as
Purchases
2 Pens
3 Books
4 Pens
1 Gifts
2 Books
I want to split it as
Col1 Col2 Col3
2Pens 3Books 1Gift
4Pens 2Books
In Excel O365, you could use in C1:
=FILTER($A1:$A5,ISNUMBER(SEARCH("* "&INDEX(UNIQUE(MID($A1:$A5,FIND(" ",$A1:$A5)+1,LEN($A1:$A5))),COLUMN(A1)),$A1:$A5)))
Drag the formula right.

Find the corresponding value in a separate table depending on another table in Excel

I am trying to find the value in one table (Table 2), based on the location of a "Yes" in another table (Table 1). See below:
Table 1
Header1 Unique1 Unique2 Unique3
Row1 Yes
Row2 Yes
Row3 Yes
Table 2
Header1 Unique1 Unique2 Unique3
Row1 XXX
Row2 YYY
Row3 ZZZ
On another sheet, I have a column with "Unique1" or "Unique2" as follows and am trying to get the column that is labeled "Lookup":
Column1 Lookup
Unique1 XXX
Unique1 XXX
Unique3 ZZZ
Unique2 YYY
I am glad you got it working. I actually did manage to cram it into one formula.=INDEX(Sheet1!$A$5:$D$8,MATCH("Yes",INDIRECT("Sheet1!"&CHAR(CODE("A")+MATCH($A2,Sheet1!$1:$1,0)-1)&":"&CHAR(CODE("A")+MATCH($A2,Sheet1!$1:$1,0)-1)),0),MATCH($A2,Sheet1!$1:$1,0))
The way that works is it goes into your table 2 and picks out a row and a column. The column is whichever holds the name. The row gets constructed by looking for yes in the appropriate column. To name that column with a letter and not a number, I needed to convert with the whole CHAR CODE thing.

Finding and obtaining the difference between two columns

I have two columns. Each column has tens of thousands of values. I need to find the difference between them and print the difference in some cells. I read similar questions, but they are not enough for my question, highlighting the different cells is not enogh for me because it would be very tiring to look at tens of thousands of cell by searching highlighted cells. Thus, i need to obtain the values.
Example:
Column1 Column2
John Jennifer
Mary Washington
Joe John
Michael Texas
Houston Newyork
Texas Mary
Values existing in col1 but not col2 : Joe, Michael, Houston
Values existing in col1 but not col2 : Jennifer, Washington, New York
Algorithmically, i need to check each row of column1 whether it exists in Column2, if the row does not exist in Column2, the value is taken.
Similarly, i need to check each row of column2 whether it exists in Column1, if the row does not exist in Column1, the value is taken.
Thanks
Old: If this is a once-off i'd make a backup then mark the area of the two columns and "remove duplicates" which is a button on the DATA command bar.
You would be left with unique records only, which is what I understand you want.
Edit: If you want to completely remove duplicate values then: Assuming that col1 is "A" and col2 is "B" then this formula only shows the record if it is in A but not in B. You can make a similar one for B not in A. In my example I made two columns C, D for the unique values. Then filter the list on these being "not nothing", and you have a set of unique records.
Current formula is for A2 cell - in my example placed in C2.
=IF(ISERROR(MATCH(A2;B:B;0));A2;"")

How to check if value/string in one row of Table 1 is present in Table 2?

I want to check if a value or text string in a given row in Table 1 is also present in a given column in Table 2. Of course I could do this column by column in Table 1 but with about 50 columns I don't really want to. My data looks something like this:
Table 1
1 aaa bbb ccc
2 ddd eee fff
3 ggg hhh iii
Table 2
1 bbb
2 xxx
3 ccc
You could use an array formula:
=SUM(IF(COUNTIF(Sheet2!$A$1:$A$3,$A1:$C1)>0,1,0))
Press CTRL-SHIFT-ENTER after entering it as opposed to ENTER
This will tell you how many exist in the list on sheet2 for each row in sheet 1

Resources