Hola de nuevo. Ya he terminado mi proyecto, con vuestra ayuda. Pero ahora veo que uno de los procesos es muy lento. Cuando le doy a un botón ejecuta esta macro con 7 bucles, uno por semana, que recorre cada vez que lo hace 7.000 filas. Y que cada mes añadirá otras más de 2.000 filas más. Así que cada vez que ejecute la macro se me va a emplear mucho tiempo. Yo creo que con un solo bucle lo puede hacer, porque pienso que debe haber una lógica matemática que lo haga, pero yo no soy capaz de saber cómo. U otra manera que no sea con bucles...
Pego el código por si alguien de vosotros podría ayudarme. Ya veis que repito el código cada día de la semana y que los textbox son correlativos, por ejemplo TextboxE1 es lunes, TextboxE2 es martes, etc..
Gracias por adelantado.
Private Sub Boton1_Click()
With Sheets("Registro_Instaladores")
uf1 = .Cells(Rows.Count, "B").End(xlUp).Row
'lunes
For t = 4 To uf1
If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = ComboBox9.Text Then
.Cells(t, 8).Value = Left(TextBoxE1.Text, 2) & Right(TextBoxE1.Text, 2)
.Cells(t, 9).Value = Left(TextBoxS1.Text, 2) & Right(TextBoxS1.Text, 2)
.Cells(t, 10).Value = Left(TextBoxN1.Text, 2) & Right(TextBoxN1.Text, 2)
.Cells(t, 13).Value = ComboBox2.Text
.Cells(t, 16).Value = TextBoxO1.Text
End If
Next
'martes
For t = 4 To uf1
If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = TextBoxF2.Text Then
.Cells(t, 8).Value = Left(TextBoxE2.Text, 2) & Right(TextBoxE2.Text, 2)
.Cells(t, 9).Value = Left(TextBoxS2.Text, 2) & Right(TextBoxS2.Text, 2)
.Cells(t, 10).Value = Left(TextBoxN2.Text, 2) & Right(TextBoxN2.Text, 2)
.Cells(t, 13).Value = ComboBox3.Text
.Cells(t, 16).Value = TextBoxO2.Text
End If
Next
'miercoles
For t = 4 To uf1
If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = TextBoxF3.Text Then
.Cells(t, 8).Value = Left(TextBoxE3.Text, 2) & Right(TextBoxE3.Text, 2)
.Cells(t, 9).Value = Left(TextBoxS3.Text, 2) & Right(TextBoxS3.Text, 2)
.Cells(t, 10).Value = Left(TextBoxN3.Text, 2) & Right(TextBoxN3.Text, 2)
.Cells(t, 13).Value = ComboBox4.Text
.Cells(t, 16).Value = TextBoxO3.Text
End If
Next
'jueves
For t = 4 To uf1
If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = TextBoxF4.Text Then
.Cells(t, 8).Value = Left(TextBoxE4.Text, 2) & Right(TextBoxE4.Text, 2)
.Cells(t, 9).Value = Left(TextBoxS4.Text, 2) & Right(TextBoxS4.Text, 2)
.Cells(t, 10).Value = Left(TextBoxN4.Text, 2) & Right(TextBoxN4.Text, 2)
.Cells(t, 13).Value = ComboBox5.Text
.Cells(t, 16).Value = TextBoxO4.Text
End If
Next
'viernes
For t = 4 To uf1
If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = TextBoxF5.Text Then
.Cells(t, 8).Value = Left(TextBoxE5.Text, 2) & Right(TextBoxE5.Text, 2)
.Cells(t, 9).Value = Left(TextBoxS5.Text, 2) & Right(TextBoxS5.Text, 2)
.Cells(t, 10).Value = Left(TextBoxN5.Text, 2) & Right(TextBoxN5.Text, 2)
.Cells(t, 13).Value = ComboBox6.Text
.Cells(t, 16).Value = TextBoxO5.Text
End If
Next
'sabado
For t = 4 To uf1
If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = TextBoxF6.Text Then
.Cells(t, 8).Value = Left(TextBoxE6.Text, 2) & Right(TextBoxE6.Text, 2)
.Cells(t, 9).Value = Left(TextBoxS6.Text, 2) & Right(TextBoxS6.Text, 2)
.Cells(t, 10).Value = Left(TextBoxN6.Text, 2) & Right(TextBoxN6.Text, 2)
.Cells(t, 13).Value = ComboBox7.Text
.Cells(t, 16).Value = TextBoxO6.Text
End If
Next
'domingo
For t = 4 To uf1
If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = TextBoxF7.Text Then
.Cells(t, 8).Value = Left(TextBoxE7.Text, 2) & Right(TextBoxE7.Text, 2)
.Cells(t, 9).Value = Left(TextBoxS7.Text, 2) & Right(TextBoxS7.Text, 2)
.Cells(t, 10).Value = Left(TextBoxN7.Text, 2) & Right(TextBoxN7.Text, 2)
.Cells(t, 13).Value = ComboBox8.Text
.Cells(t, 16).Value = TextBoxO7.Text
End If
Next
End With
LimpiarTextbox
Bt_Buscar
End Sub
Featured Replies
Archivado
Este tema está ahora archivado y está cerrado a más respuestas.
Hola de nuevo. Ya he terminado mi proyecto, con vuestra ayuda. Pero ahora veo que uno de los procesos es muy lento. Cuando le doy a un botón ejecuta esta macro con 7 bucles, uno por semana, que recorre cada vez que lo hace 7.000 filas. Y que cada mes añadirá otras más de 2.000 filas más. Así que cada vez que ejecute la macro se me va a emplear mucho tiempo. Yo creo que con un solo bucle lo puede hacer, porque pienso que debe haber una lógica matemática que lo haga, pero yo no soy capaz de saber cómo. U otra manera que no sea con bucles...
Pego el código por si alguien de vosotros podría ayudarme. Ya veis que repito el código cada día de la semana y que los textbox son correlativos, por ejemplo TextboxE1 es lunes, TextboxE2 es martes, etc..
Gracias por adelantado.
Private Sub Boton1_Click() With Sheets("Registro_Instaladores") uf1 = .Cells(Rows.Count, "B").End(xlUp).Row 'lunes For t = 4 To uf1 If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = ComboBox9.Text Then .Cells(t, 8).Value = Left(TextBoxE1.Text, 2) & Right(TextBoxE1.Text, 2) .Cells(t, 9).Value = Left(TextBoxS1.Text, 2) & Right(TextBoxS1.Text, 2) .Cells(t, 10).Value = Left(TextBoxN1.Text, 2) & Right(TextBoxN1.Text, 2) .Cells(t, 13).Value = ComboBox2.Text .Cells(t, 16).Value = TextBoxO1.Text End If Next 'martes For t = 4 To uf1 If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = TextBoxF2.Text Then .Cells(t, 8).Value = Left(TextBoxE2.Text, 2) & Right(TextBoxE2.Text, 2) .Cells(t, 9).Value = Left(TextBoxS2.Text, 2) & Right(TextBoxS2.Text, 2) .Cells(t, 10).Value = Left(TextBoxN2.Text, 2) & Right(TextBoxN2.Text, 2) .Cells(t, 13).Value = ComboBox3.Text .Cells(t, 16).Value = TextBoxO2.Text End If Next 'miercoles For t = 4 To uf1 If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = TextBoxF3.Text Then .Cells(t, 8).Value = Left(TextBoxE3.Text, 2) & Right(TextBoxE3.Text, 2) .Cells(t, 9).Value = Left(TextBoxS3.Text, 2) & Right(TextBoxS3.Text, 2) .Cells(t, 10).Value = Left(TextBoxN3.Text, 2) & Right(TextBoxN3.Text, 2) .Cells(t, 13).Value = ComboBox4.Text .Cells(t, 16).Value = TextBoxO3.Text End If Next 'jueves For t = 4 To uf1 If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = TextBoxF4.Text Then .Cells(t, 8).Value = Left(TextBoxE4.Text, 2) & Right(TextBoxE4.Text, 2) .Cells(t, 9).Value = Left(TextBoxS4.Text, 2) & Right(TextBoxS4.Text, 2) .Cells(t, 10).Value = Left(TextBoxN4.Text, 2) & Right(TextBoxN4.Text, 2) .Cells(t, 13).Value = ComboBox5.Text .Cells(t, 16).Value = TextBoxO4.Text End If Next 'viernes For t = 4 To uf1 If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = TextBoxF5.Text Then .Cells(t, 8).Value = Left(TextBoxE5.Text, 2) & Right(TextBoxE5.Text, 2) .Cells(t, 9).Value = Left(TextBoxS5.Text, 2) & Right(TextBoxS5.Text, 2) .Cells(t, 10).Value = Left(TextBoxN5.Text, 2) & Right(TextBoxN5.Text, 2) .Cells(t, 13).Value = ComboBox6.Text .Cells(t, 16).Value = TextBoxO5.Text End If Next 'sabado For t = 4 To uf1 If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = TextBoxF6.Text Then .Cells(t, 8).Value = Left(TextBoxE6.Text, 2) & Right(TextBoxE6.Text, 2) .Cells(t, 9).Value = Left(TextBoxS6.Text, 2) & Right(TextBoxS6.Text, 2) .Cells(t, 10).Value = Left(TextBoxN6.Text, 2) & Right(TextBoxN6.Text, 2) .Cells(t, 13).Value = ComboBox7.Text .Cells(t, 16).Value = TextBoxO6.Text End If Next 'domingo For t = 4 To uf1 If .Cells(t, 2).Value = ComboBox1.Text And .Cells(t, 7).Value = TextBoxF7.Text Then .Cells(t, 8).Value = Left(TextBoxE7.Text, 2) & Right(TextBoxE7.Text, 2) .Cells(t, 9).Value = Left(TextBoxS7.Text, 2) & Right(TextBoxS7.Text, 2) .Cells(t, 10).Value = Left(TextBoxN7.Text, 2) & Right(TextBoxN7.Text, 2) .Cells(t, 13).Value = ComboBox8.Text .Cells(t, 16).Value = TextBoxO7.Text End If Next End With LimpiarTextbox Bt_Buscar End Sub