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:
The items in the dropdown list are dates, formatted as dates in the worksheet.
then I am defining the date selected as:
In the next sub I have the following code:
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
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
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