Copiar textbox en diferentes columnas según lo seleccionado en el combobox

Tengo lo siguiente el combobox con tipo de moneda con los valores soles y dolares

Lo que necesito es que al selccionar un tipo de moneda del combobox el monto ingresado en el textbox se copie en la columna que le corresponda, en caso sea soles en la columna I, y en caso sea dolares en la columna J

2 respuestas

Respuesta
1

Macro

Private Sub CommandButton1_Click()
Dim i
    Set h = Sheets("Hoja3")
    Select Case ComboBox1.ListIndex
        Case 0: col = "I"
        Case 1: col = "J"
    End Select
    '
     i = 6
    Do While Cells(i, col) <> ""
        i = i + 1
    Loop
    h.Cells(i, col) = Val(TextBox1.Text)
End Sub
Private Sub UserForm_Initialize()
ComboBox1. AddItem "soles"
ComboBox1. AddItem "dolares"
End Sub

valora ésta respuesta para finalizar 

Estimado copie el código indicado pero al momento de ejecutarlo el monto en dolares no lo copia en la siguiente celda, este es el código en general donde lo eh colocado, alguna sugerencia

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 ComboBox1 = "" Or ComboBox2 = "" Or ComboBox3 = "" Or ComboBox4 = "" Or ComboBox5 = "" Then
MsgBox "Escriba todos los datos"


Else
Dim i
Set h = Sheets("ON TRADE- MAYORISTAS FY20")
Select Case ComboBox4.ListIndex
Case 0: col = "I"
Case 1: col = "J"
End Select
i = 6
Do While Cells(i, col) <> ""
i = i + 1
Loop
h.Cells(i, col) = Val(TextBox5.Text)

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) = ComboBox2
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 5) = TextBox3
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 6) = ComboBox3
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 7) = TextBox4
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 8) = ComboBox4
Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 11) = ComboBox5
x = ult + 1
rango = "A" & x & ":L" & x
Sheets("ON TRADE- MAYORISTAS FY20").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 = ""
ComboBox1.Text = ""
ComboBox2.Text = ""
ComboBox3.Text = ""
ComboBox4.Text = ""
ComboBox5.Text = ""

TextBox1.SetFocus

Else
Unload Me
UserForm1.Show
End If

Macro actualizada

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 ComboBox1 = "" Or ComboBox2 = "" Or ComboBox3 = "" Or ComboBox4 = "" Or ComboBox5 = "" Then
    MsgBox "Escriba todos los datos"
    Else
    Select Case ComboBox4.ListIndex
        Case 0: col = "I" ' soles
        Case 1: col = "J" ' 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) = ComboBox2
    Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 5) = TextBox3
    Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 6) = ComboBox3
    Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 7) = TextBox4
    Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 8) = ComboBox4
    Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, col) = TextBox1 ' soles o dólares
    Sheets("ON TRADE- MAYORISTAS FY20").Cells(ult + 1, 11) = ComboBox5
    x = ult + 1
    rango = "A" & x & ":L" & x
    Sheets("ON TRADE- MAYORISTAS FY20").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 = ""
    ComboBox1.Text = ""
    ComboBox2.Text = ""
    ComboBox3.Text = ""
    ComboBox4.Text = ""
    ComboBox5.Text = ""
    TextBox1.SetFocus
    Else
    Unload Me
    UserForm1.Show
End If
Respuesta
1

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas