VBA Find from list

mribadeneira

New Member
Joined
Apr 10, 2013
Messages
7
I have a rpoblem finding items from a list. I have a userform with a dropdown (ElegirFecha) menu thats filled with the code:
Code:
Set dicFecha = CreateObject("Scripting.Dictionary")
Sheets("Datos").Select
Range("A2").Select
    With ElegirFecha
        .Clear
    End With

    For Each rngCell In Range(Selection, Selection.End(xlDown))
        If dicFecha.Exists(rngCell.Value) = False Then
            dicFecha.Add rngCell.Value, Nothing
            With ElegirFecha
                .AddItem rngCell.Value
            End With
        End If
    Next rngCell
The items in the dropdown list are dates, formatted as dates in the worksheet.
then I am defining the date selected as:
Code:
fecha = opcion1.ElegirFecha.Value

In the next sub I have the following code:
Code:
Private Sub CollectDataOp1()
Dim Itm
Sheets("Datos").Select
Range("A1").Select
With Worksheets("Datos").Range(Selection, Selection.End(xlDown))
    Set c = .Find(what:=fecha, LookIn:=xlValues)
    If Not c Is Nothing Then
        firstaddress = c.Address
        
    For Each Itm In Array(NB1, NB2, NB3, NB4, NB5, NB6, NB7, NB8)
        Do
            If c.Offset(0, 2).Value = Itm & " " & r1 Then
                If opcion1.TEA.Value = True Then
                    BP1 = c.Offset(0, 4)
                    Sheets("Resultados").Select
                    Range("Z3").End(xlToLeft).Offset(0, 1).Select
                    ActiveCell.Value = BP1
                    Sheets("Datos").Select
                End If
                If opcion1.Participacion.Value = True Then
                    BP1 = c.Offset(0, 5)
                    Sheets("Resultados").Select
                    Range("Z3").End(xlToLeft).Offset(0, 1).Select
                    ActiveCell.Value = BP1
                    Sheets("Datos").Select
                End If
                If opcion1.Monto.Value = True Then
                    BP1 = c.Offset(0, 6)
                    Sheets("Resultados").Select
                    Range("Z3").End(xlToLeft).Offset(0, 1).Select
                    ActiveCell.Value = BP1
                    Sheets("Datos").Select
                End If
            End If
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstaddress
    Next Itm
        
    End If
End With

End Sub

It works fine if ytou select dates from the first part of the list. However the find only matches about the first half of the dates, and if you select a date near the bottom of the list it doesn't find any matches and goes straight to End If.
Why/how is this happening if both the list generated, and the find function are working in the same range?

Please help if you can :)
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
There are about 45,000 rows of data, and the list is of about 300 dates, each repeated about 150 times. Is there a limit as to how big a raange can be for it to be searchable, or is there some other problem?
 
Upvote 0

Forum statistics

Threads
1,203,607
Messages
6,056,285
Members
444,855
Latest member
archadiel

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