Macro VBA to find row from two different column

kayza

Board Regular
Joined
Apr 29, 2015
Messages
61
Office Version
  1. 2007
Platform
  1. Windows
Hello everyone,
I need help finding the location of rows from 2 different criteria that are in 2 different columns. and here is an example of the data that I have which is located in sheet1
[TABLE="class: grid, width: 300, align: left"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Data-1[/TD]
[TD]Data-2[/TD]
[TD][/TD]
[TD]FIND :[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]ec[/TD]
[TD]x[/TD]
[TD][/TD]
[TD]ec[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]ec[/TD]
[TD]z1[/TD]
[TD][/TD]
[TD]v7[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]dh[/TD]
[TD]r[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]ec[/TD]
[TD]v7[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]dh[/TD]
[TD]kr[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]sp[/TD]
[TD]ro[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]...[/TD]
[TD]...[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Example of the results I want to show are as follows :

If the value in cell D2 = ec and cell D3 = v7
then the message box will display the row location (5)



Any help is appreciated. Thanks!

Kayza
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
This should work:

Code:
'array parameters
fr = 2 'first row with data
lr = Range("A" & Rows.Count).End(xlUp).Row 'calculate last row
fc = 1 'first column of data

'search parameters
search1 = Range("D2").Value 'first searched for value
search2 = Range("D3").Value 'second searched for value

'create array and complete searches
arr = Range(Cells(fr, fc), Cells(lr, fc + 1))
For i = LBound(arr) To UBound(arr)
    If arr(i, 1) = search1 Then
        If arr(i, 2) = search2 Then
            MsgBox "Found in row " & i + fr - 1
        End If
    End If
Next
 
Upvote 0
Thanks for your Quick response
its work like a charm

thanks
 
Upvote 0
Try this:

Code:
Sub Find_Me()
'Modified 8/2/2019 4:59:33 AM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim ans As String
ans = "No"
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To Lastrow
If Cells(i, 1).Value = Range("D2").Value And Cells(i, 2).Value = Range("D3").Value Then ans = "Yes": MsgBox "Found on Row  " & i: Exit Sub
Next
If ans = "No" Then MsgBox "Not found"
Application.ScreenUpdating = True
End Sub
 
Upvote 0
I note that you have asked for a macro but in case that is not vital for you this formula suggestion may be of use.

Excel Workbook
ABCD
1Data-1Data-2FIND :
2ecxec
3ecz1v7
4dhr5
5ecv7
6dhkr
7spro
8
Row Found



If you really do need/want a macro then you could try

Code:
Sub Find_Row()
  MsgBox Evaluate("AGGREGATE(15,6,ROW(A1:A2000)/((A1:A2000=D2)*(B1:B2000=D3)),1)")
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,953
Messages
6,175,598
Members
452,658
Latest member
GStorm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top