Te anexo el código para cargar los datos únicos en el combo:
Private Sub UserForm_Activate()
'Por.Dante Amor
Set h1 = Sheets("base de datos")
For i = 2 To h1.Range("A" & Rows.Count).End(xlUp).Row
agregar ComboBox1, h1.Cells(i, "A")
Next
End Sub
Sub agregar(combo As ComboBox, dato As String)
'Por.Dante Amor
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 SubY el siguiente código es para llenar los textbox
Private Sub ComboBox1_Change()
'Por.Dante Amor
Set h1 = Sheets("base de datos")
Set r = h1.Columns("A")
Set b = r.Find(ComboBox1, lookat:=xlWhole)
If Not b Is Nothing Then
ncell = b.Address
Do
Select Case h1.Cells(b.Row, "B")
Case 1: TextBox1 = Val(TextBox1) + h1.Cells(b.Row, "D")
Case 2: TextBox2 = Val(TextBox2) + h1.Cells(b.Row, "D")
Case 3: TextBox3 = Val(TextBox3) + h1.Cells(b.Row, "D")
Case 4: TextBox4 = Val(TextBox4) + h1.Cells(b.Row, "D")
Case 5: TextBox5 = Val(TextBox5) + h1.Cells(b.Row, "D")
Case 6: TextBox6 = Val(TextBox6) + h1.Cells(b.Row, "D")
Case 7: TextBox7 = Val(TextBox7) + h1.Cells(b.Row, "D")
Case 8: TextBox8 = Val(TextBox8) + h1.Cells(b.Row, "D")
Case 9: TextBox9 = Val(TextBox9) + h1.Cells(b.Row, "D")
Case 10: TextBox10 = Val(TextBox10) + h1.Cells(b.Row, "D")
Case 11: TextBox11 = Val(TextBox11) + h1.Cells(b.Row, "D")
Case 12: TextBox12 = Val(TextBox12) + h1.Cells(b.Row, "D")
End Select
Set b = r.FindNext(b)
Loop While Not b Is Nothing And b.Address <> ncell
End If
End Sub
Estoy asumiendo varias cosas que no comentaste que deberás ajustar en la macro:
- El nombre de la hoja de tu base de datos, le puse "base de datos", busca este nombre en la macro y cámbialo.
- En la columna A el producto, en la B el mes, en la C el año y en la D el valor.
- Que tienes como mes los números del 1 al 12.
- Que tu combo es el combobox1
- Que los textbox para los meses van del texbox1 al textbox12.
Si tienes dudas para actualizar los datos avísame.
Saludos. Dante Amor
Si es lo que necesitas.