Buscar y cargar combobox excel vba

[Hola a todos los experimentados en la programación

necesito cargar datos al combobox de acuerdo a la categoría.

Según el ejemplo busco la categoría B a través de un textbox y debe cargar el comboxbox (3,4,5,6)

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Set h1 = Sheets("Hoja1")
    '
    Set r = h1.Columns("A")
    Set b = r.Find(TextBox1, lookat:=xlWhole)
    If Not b Is Nothing Then
        For i = 2 To Cells(b.Row, 3).MergeArea.Cells.Count
            ComboBox1.AddItem Cells(b.Row, 3)
        Next i
    End If
End Sub

2 respuestas

Respuesta
1

Prueba lo siguiente:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  Dim h1 As Worksheet, r As Range, b As Range, c As Range, i As Long
  Set h1 = Sheets("Hoja1")
  '
  Set r = h1.Columns("A")
  Set b = r.Find(TextBox1, , xlValues, xlWhole)
  ComboBox1.Clear
  If Not b Is Nothing Then
    If b.MergeCells Then
      For Each c In b.MergeArea.Rows
        ComboBox1.AddItem Cells(c.Row, 3)
      Next
    Else
      ComboBox1.AddItem b.Offset(, 2)
    End If
  End If
End Sub
Respuesta

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas