Como capturar datos de un formulario en vba a distintas hojas de excel a la siguiente fila vacía de cada hoja

Tengo un formulario en el cual a su ves contiene campos a llenar, como option button, combobox, textbox, y al momento de seleccionar un botón me captura esos datos en distintas hojas de excel, pero no recuerdo el uso de una variable que te captura los datos a la siguiente fila vacía, en este caso es la variable "i".

¿Existe una forma de hacerlo más fácil?

¿Cuál es la forma correcta de utilizar la variable en este caso?

Private Sub btn_cancel_Click()
End
End Sub

Private Sub btn_guardar_Click()
Dim i As Integer
i = 1

For i = 1 To 500

If combo_modelo.Text = "989" Then

If opt_tmmbc.Value = True Then
worksheets(2).Range("C" & i).Cells = "TMMBC"
Else
If opt_tmmtx.Value = True Then
worksheets(2).Range("C" & i).Cells = "TMMTX"
End If
End If

If opt_chl.Value = True Then
worksheets(2).Range("E" & i).Cells = "CHL"
Else
If opt_rcl.Value = True Then
worksheets(2).Range("E" & i).Cells = "RCL"
End If
End If

If opt_lh.Value = True Then
worksheets(2).Range("F" & i).Cells = "LH"
Else
If opt_rh.Value = True Then
worksheets(2).Range("F" & i).Cells = "RH"
End If
End If

If opt_customerdam.Value = True Then
worksheets(2).Range("S" & i).Cells = "Customer Damaged"
Else
If opt_NTF.Value = True Then
worksheets(2).Range("S" & i).Cells = "NTF"
Else

If opt_NALresp.Value = True Then
worksheets(2).Range("S" & i).Cells = "NAL Responsible"

End If
End If
End If
End If

Next i

End Sub

Private Sub btn_limpiar_Click()

txt_arrivedate.Text = Empty
txt_vinumber.Text = Empty
txt_datecode.Text = Empty
txt_condition.Text = Empty
txt_t1.Text = Empty
txt_t2.Text = Empty
txt_millas.Text = Empty
txt_repairloc.Text = Empty
txt_LO.Text = Empty
txt_regist.Text = Empty
txt_repairdate.Text = Empty
txt_conclusion.Text = Empty
opt_tmmbc.Value = False
opt_tmmtx.Value = False
opt_chl.Value = False
opt_rcl.Value = False
opt_rh.Value = False
opt_lh.Value = False
opt_customerdam.Value = False
opt_NTF.Value = False
opt_NALresp.Value = False
combo_modelo.Value = Empty
txt_arrivedate.SetFocus

End Sub

Respuesta
2

Cambia esto

i = 1
For i = 1 To 500

Por esto:

i = worksheets(2).range("C" & rows.count).end(xlup).row + 1

Y también borra la línea

Next i

'.[Sal u dos. Dante Amor. No olvides valorar la respuesta. 
'.[Avísame cualquier duda

y como le indico cual función hacer? 

Ya sea que coloque lo que tengo de mi textbox, combobox,option button, en ciertas columnas.

Gracias por el apoyo!!

No entiendo tus dudas.

¿Hiciste los cambios que te envié? ¿Probaste nuevamente?

No recuerdo muy bien el código, creo que no es así,¿podrías apoyarme con eso?

Ahoraq no me captura nada

Private Sub btn_guardar_Click()
Dim i As Integer

If combo_modelo.Text = "989" Then

If opt_tmmbc.Value = True Then
i = Worksheets(2).Range("C" & Rows.Count).End(xlUp).Row + 1 = "TMMBC"
Else
If opt_tmmtx.Value = True Then
i = Worksheets(2).Range("C" & Rows.Count).End(xlUp).Row + 1 = "TMMTX"
End If
End If

If opt_chl.Value = True Then
i = Worksheets(2).Range("E" & Rows.Count).End(xlUp).Row + 1 = "CHL"
Else
If opt_rcl.Value = True Then
i = Worksheets(2).Range("E" & Rows.Count).End(xlUp).Row + 1 = "RCL"
End If
End If

If opt_lh.Value = True Then
i = Worksheets(2).Range("F" & Rows.Count).End(xlUp).Row + 1 = "LH"
Else
If opt_rh.Value = True Then
i = Worksheets(2).Range("F" & Rows.Count).End(xlUp).Row + 1 = "RH"
End If
End If

If opt_customerdam.Value = True Then
i = Worksheets(2).Range("S" & Rows.Count).End(xlUp).Row + 1 = "Customer Damaged"
Else
If opt_NTF.Value = True Then
i = Worksheets(2).Range("S" & Rows.Count).End(xlUp).Row + 1 = "NTF"
Else

If opt_NALresp.Value = True Then
i = Worksheets(2).Range("S" & Rows.Count).End(xlUp).Row + 1 = "NAL Responsible"


End If
End If
End If
End If

End Sub

No entiendo a qué te refieres con:

No recuerdo muy bien el código

¿Quieres qué te ayude con todo el código o solamente con la variable i?


Yo te envié esto:

i = worksheets(2).range("C" & rows.count).end(xlup).row + 1

Y tu pones esto:

i = Worksheets(2).Range("C" & Rows.Count).End(xlUp).Row + 1 = "TMMBC"

Además pusiste la línea en otra parte.

Debes seguir las indicaciones tal y como te las envié, de lo contrario no va a funcionar.

Podrías apoyarme con el código completo?  

Pon la siguiente información

- Una imagen de tu userform

- Cómo se llama tu hoja donde quieres poner la información

- Cómo se llama cada control que tienes en tu userform

- Qué controles quieres poner en la hoja y en cuál columna va cada control

- Una imagen de tu hoja con un ejemplo de cómo van a quedar los datos en la hoja, procura que en las imágenes se vean las filas y las columnas de excel.

______________________________________________________________________________________________

Si el "model code" es "989" los datos se guardan en la hoja "989"

Si el "model code" es "480" los datos se guardan en la hoja "480"

La seccion de "location" se deben registrar los datos en la hoja "location"

______________________________________________________________________________________________

Controles:

Arrive date = txt_arrivedate

VIN number = txt_vinumber

Customer ( TMMBC) = opt_tmmbc

Customer (TMMTX) =opt_tmmtx

Model code = combo_modelo

Model (CHL) = opt_chl
Model (RCL) = opt_rcl

Side (RH) = opt_rh
Side (LH) = opt_lh

Date code = txt_datecode

Condition = txt_condition
T1 = txt_t1
T2 = txt_t2
Millage = txt_millas
Repair location = txt_repairloc
L/O date = txt_LO
Regist date = txt_regist
Repair date = txt_repairdate

Rack = txt_rack

Row = txt_row

Space = txt_space
Conclution = txt_conclusion
Clasification (customer damage) = opt_customerdam
Clasification (No trouble found identified) = opt_NTF
Clasification (Our responsible) = opt_NALresp
______________________________________________________________________________________________

hoja "480"

hoja "989"

Hoja "racks"

__________________________________________________________________________________________

Cada encabezado tiene el nombre del control que tengo en el userform 

Gracias por le apoyo nuevamente !!

Envíame tu archivo

Mi correo [email protected]

En el asunto del correo escribe tu nombre de usuario “”

1 respuesta más de otro experto

Respuesta

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas