find string in other column but same row vba - excel

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

Related

Filter Excel table if select cell values are true using VBA

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!

Sorting rows by matching values in two different columns

I have to look through my worksheet to find duplicate entries on the basis of two columns - column A and column D. If entries under both these columns match in any two given rows, then I consider them duplicated. In order to do this, I have been trying to sort the rows such that rows with matching entries under column A and column D appear one below the other. For example, if I have:
Col A Col B Col C Col D
ABC PQR 123 456
ABC XYZ 789 006
ABC BNM 376 456
ABC QWR 387 006
Preferably through VBA, I want to be able to put it in the format:
Col A Col B Col C Col D
ABC PQR 123 456
ABC BNM 376 456
ABC XYZ 789 006
ABC QWR 387 006
I am aware of how to sort by one column but not sure if there is a way to do it by two. There are more than 5000 rows in the worksheet and more than 50 columns and I would like to be able to sort these quickly for comparison.
Excel has built-in functions to help you with the issue (no VBA required).
Select the cells including your data and navigate to "Data - Sort & Filter - Sort". There you can add different levels of sorting (e.g. sort by Col A first, then by Col B, ...).
If the duplicates need to be removed this can be done directly as well. Select the cells including your data and navigate to "Data - Data Tools - Remove Duplicates". You can select the columns which need to match in order for Excel to remove the duplicates.

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.

Find duplicates with a suffix in excel and keep results

I have a spreadsheet with a list of items in one column (A) and in column C shows the total sold. I'm trying to find all the items within column A.
The issue is, some items are the same, only they have a suffix, mostly separated by a -. The values in column C would be different as well.
Example:
ABC = 5
ABC-123 = 3
ABC-543 = 2
I'm looking to identify only 123 and then combine all the values, so that it will show ABC and 10 as the total.
I've looked around how to remove the duplicate suffix, but have so far failed to find a method when trying to add the total values.
Many thanks
do you mean the data you have looks like this:
column A column B column C
ABC 5
ABC-123 3
ABC-543 2
if so, you can select column A then go to data then text to columns then delimited select other by putting - sign, next and finish.
result must be:
column A column B column C
ABC 5
ABC 123 3
ABC 543 2
then you can =sumifs(C:C;A:A;"ABC") (keep in mind that column B must be empty)
if you have ABC-123 = 3 in the same cell as a text, then you can do:
=IF(SEARCH("ABC";F3);RIGHT(F3;LEN(F3)-FIND("=";F3)-1);"")
where F3 is equal to ABC-123 = 3 The formula above searches fo ABC and gives you a value after = sign, no matter how long this value is. If there is no ABC it will return an error.
if there is no need to look for ABC then just use:
=RIGHT(F3;LEN(F3)-FIND("=";F3)-1)
I hope this helps. I cannot comment, so ask if you have questions.
Best - AB

Adding corresponding column A values if values in column B match one another

I need to create a formula that adds up column A if the values in column B match.
A B
1 123
1 123
2 345
2 345
1 345
So for this example I need it to add up 123's to show 2 and 345's to show 5. I have been playing with SUMIF and VLOOKUP but haven't been able to get it to work.
In row2 and copied down to suit:
=SUMIF(B:B,B2,A:A)

Resources