myFind Range not working

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
Please can someone say why this myFindRng goes red in the code?

VBA Code:
Private Sub Model_Chose_Change()

With ThisWorkbook.Worksheets("Job Card Master")

Me.Quote_Details.ListIndex = Me.Model_Chose.ListIndex
myValToFind = Make_Chose.Value
Set mySearchRng = .Columns("A")
End With

Set myFindRng = mySearchRng.Find(What:=myValToFind, _
           LookIn:=xlFormulas, _
           LookAt:=xlWhole, _
           SearchOrder:=xlByRows, _
           SearchDirection:=xlNext, _
           MatchCase:=False)
 
Last edited:
Here you go
Sorry to be thick

VBA Code:
[I]Private Sub Model_Chose_Change()

Dim ws          As Worksheet
Dim myFindRng   As Range, mySearchRng As Range
Dim myValToFind As Variant

Set ws = ThisWorkbook.Worksheets("Quote Detail")

With ws

Me.Quote_Details.ListIndex = Me.Model_Chose.ListIndex
myValToFind = Model_Chose.Value
Set mySearchRng = .Columns("A")
End With

Set myFindRng = mySearchRng.Find(What:=myValToFind, _
           LookIn:=xlFormulas, _
           LookAt:=xlWhole, _
           SearchOrder:=xlByRows, _
           SearchDirection:=xlNext, _
           MatchCase:=False)
           
           Quote_Details.MatchEntry
           With Me.Quote_Details
                 .List(.ListCount - 1, 0) = myFindRng.Value
                 .List(.ListCount - 1, 1) = myFindRng.Offset(0, 2).Value
                 .List(.ListCount - 1, 2) = myFindRng.Offset(0, 3).Value
                 .List(.ListCount - 1, 3) = myFindRng.Offset(0, 4).Value
                 .List(.ListCount - 1, 4) = myFindRng.Offset(0, 5).Value
                 .List(.ListCount - 1, 5) = myFindRng.Offset(0, 6).Value
                 .List(.ListCount - 1, 6) = myFindRng.Offset(0, 7).Value
                 .List(.ListCount - 1, 7) = myFindRng.Offset(0, 8).Value
                 .List(.ListCount - 1, 8) = myFindRng.Offset(0, 9).Value
                 .List(.ListCount - 1, 9) = myFindRng.Offset(0, 10).Value
                 
                End With
                

End Sub[/I]
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You should always check that the value was found before you try to use the found cell:

Code:
         If myFindRng Is Nothing then
               msgbox myvaltofind & " was not found", vbokonly
        else
           'Quote_Details.MatchEntry <- this line doesn't do anything
           With Me.Quote_Details
                 .List(.ListCount - 1, 0) = myFindRng.Value
                 .List(.ListCount - 1, 1) = myFindRng.Offset(0, 2).Value
                 .List(.ListCount - 1, 2) = myFindRng.Offset(0, 3).Value
                 .List(.ListCount - 1, 3) = myFindRng.Offset(0, 4).Value
                 .List(.ListCount - 1, 4) = myFindRng.Offset(0, 5).Value
                 .List(.ListCount - 1, 5) = myFindRng.Offset(0, 6).Value
                 .List(.ListCount - 1, 6) = myFindRng.Offset(0, 7).Value
                 .List(.ListCount - 1, 7) = myFindRng.Offset(0, 8).Value
                 .List(.ListCount - 1, 8) = myFindRng.Offset(0, 9).Value
                 .List(.ListCount - 1, 9) = myFindRng.Offset(0, 10).Value
                 
                End With
            end if
 
Upvote 0
It`s still not filtering?
There is a Vehicle column (Column B in Quote Detail Sheet) so we need to select all the vehicles of a certain Model then filter the ListBox.
 
Upvote 0
I don't see anything that looks like filtering in that code. All it appears to do is overwrite the last item in the list with the details from the found value.
 
Upvote 0
It looks like (not for the first time) you've randomly changed parts of your code. This line:

Code:
Quote_Details.MatchEntry

should have stayed as it was originally:

Code:
Quote_Details.AddItem
 
Upvote 0
I have changed it back to Quote_Details.AddItem but it`s still failing to work.
The reason why I changed it was the first time I tried to use Quote_Details.AddItem it failed so I was trying to sort it out.
 
Upvote 0
You need to give us more information. Would you take your car to a garage, point at it and say "it doesn't work" and expect them to be able to diagnose it? ;)
 
Upvote 0
I am trying to filter the Listbox with a combo box value with this code.
It`s taking the data from a worksheet adding it to a Listbox then I am using a combo box to filter the data in the Listbox.
The Worksheet with the data that is in Worksheet "Quote Details" column B.
Then the data for the Combo box is in the UserForm_Initialize code.
When it pick my value from the Combo box List it needs to filter the Listbox.

Is that clear?
 
Upvote 0
What I want to know is what is happening currently? "Failing to work" doesn't really tell me anything.
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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