Registrar formulario en diferentes hojas al seleccionar un combobox
Cuento con el siguiente código, lo que quisiera es que al seleccionar el datos"MODERNO" del combobox2, los datos se registren en la hoja "SMK FY20", la cual tiene las misma características que la hoja en la cual se están copiando los datos
Private Sub CommandButton1_Click()
ult = Sheets("ON TRADE- MAYORISTAS FY20").Cells(Rows.Count, 6).End(xlUp).Row
If TextBox1 = "" Or TextBox2 = "" Or TextBox3 = "" Or TextBox4 = "" Or TextBox5 = "" Or TextBox6 = "" Or ComboBox1 = "" Or ComboBox2 = "" Or ComboBox3 = "" Or ComboBox4 = "" Or ComboBox5 = "" Then
MsgBox "Escriba todos los datos"
Else
Select Case ComboBox4.ListIndex
Case 0: col = "J" ' soles
Case 1: col = "K" ' dolares
End Select
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 1) = TextBox1
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 2) = CDate(TextBox2)
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 3) = ComboBox1
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 4) = TextBox6
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 5) = ComboBox2
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 6) = TextBox3
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 7) = ComboBox3
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 8) = TextBox4
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 9) = ComboBox4
If col = "J" Then
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, col).NumberFormat = "[$S/-es-PE]* #,##0.00"
Else
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, col).NumberFormat = "[$$-en-US]* #,##0.00"
End If
'
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, col) = Val(TextBox5.Text) ' soles o dólares
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 12) = ComboBox5
x = ult + 1
rango = "A" & x & ":L" & x
Sheets("FORMULARIO").Select
Range(rango).Select
MsgBox "Se ha escrito correctamente su registro"
response = MsgBox("¿Desea añadir otro registro?", _
vbYesNo)
If response = vbYes Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
ComboBox1.Text = ""
ComboBox2.Text = ""
ComboBox3.Text = ""
ComboBox4.Text = ""
ComboBox5.Text = ""
TextBox1.SetFocus
Else
Unload Me
UserForm1.Show
End If
End If
End Sub
2 respuestas
Respuesta de Dante Amor
1
Respuesta de Programar Excel
1