Duda con for each...next para aplicar un bucle y reducir código

hola tengo la siguiente macro: me gustaría reducir código y aprender como hacer un bucle con textbox

Dim wka2 As Worksheet
Set wka2 = ThisWorkbook.Sheets("calendar")
If TextBox1 = "" And TextBox2 = "" And TextBox3 = "" And TextBox4 = "" And TextBox5 = "" And TextBox7 = "" Then
Exit Sub
Else
If MsgBox("Atención!!,¿Estas seguro que quiere modificar las fechas?", vbOKCancel) = True Then
wka2.Range("ac9") = CDate(TextBox1)
wka2.Range("ac10") = CDate(TextBox2)
wka2.Range("ac11") = CDate(TextBox3)
wka2.Range("ac12") = CDate(TextBox4)
wka2.Range("ac13") = CDate(TextBox5)
wka2.Range("ac14") = CDate(TextBox7)
Else
Exit Sub
End If
End If
End Sub

he intentado lo siguiente pero no llego

dim as byte

for i = 1 to 7

wka2.Range("ac" i + 8) = CDate(TextBox1) ' pero no se como hacerlo con el textbox

next

Gracias

1 Respuesta

Respuesta
1

Prueba con lo siguiente

fila = 9
For Each ctrl In Me.Controls
If TypeName(ctrl) = "TextBox" Then
Cells(fila, "AC").Value = CDate(ctrl.Value)
fila = fila + 1
End If
Next

Saludos. Dam
Si es lo que necesitas.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas