Seleccionar otro valor desde un combobox en Vba
Tengo un combobox en el cual se agregan valores de una columna, yo al seleccionar un valor de ese combobox me llena unos textbox, desde ahí todo bien, el problema nace cuando quiero llenar el textbox1 con valores ubicados en otra columna.

Los valores de la columna F se guardan en el combobox1, pero me gustaría que el textbox1 se llene con el valor de la columna N, he realizado for que me recorran la columna M y si el valor es igual al combobox1 me incluya el valor de la columna N, pero no me resulta.
Adjunto código
Sub Agregar(combo As ComboBox, dato As String)
For i = 0 To combo.ListCount - 1
Select Case StrComp(combo.List(i), dato, vbTextCompare)
Case 0: Exit Sub 'ya existe en el combo y ya no lo agrega
Case 1: combo.AddItem dato, i: Exit Sub 'Es menor, lo agrega antes del comparado
End Select
Next
combo.AddItem dato 'Es mayor lo agrega al final
End Sub
Private Sub ComboBox1_Change()
Dim i As Double
Dim w As Double
Dim final As Double
Dim final_1 As Double
var2 = ComboBox1.Column(0)
Cells.Find(What:=ComboBox1.Value, After:=ActiveCell, LookIn:=xlFormulas, lookat:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
Worksheets("Sheet1").Select
final = Application.CountA(Worksheets("Sheet1").Range("f:f"))
For i = 2 To final
Nombres = Worksheets("sheet1").Cells(i, 6).Value
If Nombres = Me.ComboBox1.Value Then
Me.TextBox2.Value = Application.CountIf(Worksheets("sheet1").Range("F1:F" & final), Nombres)
End If
Next
'Me.TextBox3 = Me.TextBox1.Value - Me.TextBox2.Value
RESULTADO = 0
For X = 2 To 100
If Cells(X, 6) = Me.ComboBox1.Value Then
RESULTADO = RESULTADO + Cells(X, 8)
Me.TextBox4.Value = RESULTADO
End If
Next
End Sub
Private Sub UserForm_Activate()
'Cargar los ámbitos
Set h = Sheets("Sheet1")
For i = 3 To h.Range("F" & Rows.Count).End(xlUp).Row
Call Agregar(ComboBox1, h.Cells(i, "F"))
Next
End Sub
1 respuesta
Respuesta de James Bond
1

