Look for EXACT value in a range

noobsauce

New Member
Joined
May 9, 2012
Messages
26
Hey guys,

I need some help with this code here.

Code:
For l = 1 To myrange.Rows.Count
        
    'looking for MRQ
        Set rngFndb = .Columns(mrq).Find(myrange(l, 1))
        If rngFndb Is Nothing Then
            k = 0
        Else
            k = rngFndb.Row

It was working find until I accidentally stumbbled across a major issue. First of all myrange is selected via input box and it contains a list of activity codes. Now my macro uses the values in myrange to get coressponding values from another excel workbook. The issue I'm running across is the fact that in myrange there are codes which are very similiar (ie. PR4500 vs. PR45001). My macro is have trouble distinguishing between the two due to the fact that the first 6 characters are identical. I was wondering if there was a way to find EXACT value in myrange. I was thinking something like
Code:
 Set rngFndb = .columns(mrq).find(what:=myrange(l,1), after:=.cells(1,1), lookin:=xlValues, looat:=[B]xlWhole[/B], searchorder:=xlbyrows, searchdirection:=xlNext, matchcase:=false)
, but that didn't work for me =P. I hope someoen has a solution they would like to share. Thanks in advance and hope everyone is having a great weekend.

Cheers,

Noobsauce
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
shg thanks for the pick up on that, but unfortunately that's just my typo. I think the problem lies in the what:= part, I don't think it supports the myrange(l,1) object type.
 
Upvote 0
Maybe you could post your actual code. For example, there's a missing With statement used by the After argument.
 
Upvote 0
I believe this is the part of the code that is relevant...

Code:
Private Sub StartDC_Click()
Dim myrange As Range
Set myrange = Application.InputBox("Please select a range of cells", "Range", Selection.Address, , , , , 8)
Dim WB As Workbook
filetoopen = Application.GetOpenFilename(Title:="Please choose a file to import")
If filetoopen = False Then
MsgBox "No file specified.", vbExclamation, "Epic Fail"
Exit Sub
Else
Workbooks.Open Filename:=filetoopen
Set WB = ActiveWorkbook
End If
Dim mrq As Integer
Dim l As Integer

With WB.Sheets(1)
mrq = .Cells.Find("MRQ to PO").Column

Dim k As Integer

'MsgBox mrq
For l = 1 To myrange.Rows.Count

'looking for MRQ
Set rngFndb = .Columns(mrq).Find(myrange(l, 1))
If rngFndb Is Nothing Then
k = 0
Else
k = rngFndb.Row

End If
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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