Saltar al contenido

hacer una tarea repetitva con bucle


Recommended Posts

publicado

Buenas noches a todos, cuento con una macro que funciona muy bien, basicamente lo que hace es rellenar notas de estudiantes a una pagina web, situada en un boton, la cual va tomando sus valores de un textbox3  y combobox1.

entonces al escoger el numero de estudiantes en una lista de 1 a 45 situada en el combobox1, la macro comienza su funcionamiento y rellena la nota en la pagina web.

ahora la pregunta es: ¿Como hacer para que una vez escogido el numero 1 en el combobox1 y terminada su ejecucion, pase automaticamente al numero 2 de la lista, hasta el numero final establecido en la celda  "AO1", de la hoja "Sigep"?

la macro es la siguiente

On Error Resume Next

Dim busqueda
Dim datos

Dim fila
Dim columna


'validar webdriver isntanciado
Dim MyTitle As String: MyTitle = manejador.Window.Title
If MyTitle = "" Then
MsgBox "No has iniciado el navegador", vbInformation, "Información"
Exit Sub
End If

'validar estudiante esa selecionado cuando es individual
If ComboBox1.Text = "" Then
MsgBox "Debe seleccionar un Estudiante", vbInformation, "Información"
Exit Sub
End If


Set TextBox = TextBox2
fila = ComboBox1.Value + 1 'incrementar los alumnos empizan en la fila 2
'MsgBox fila

'On Error Resume Next
        'MsgBox ("No has iniciado el navegador"), vbInformation, "AVISO"
        
automatizacion.manejador.FindElementByXPath("//*[" & TextBox3.Value & "]/td[10]/div[2]/button").Click ' para estudiante individual


'esperar la ventana de las notas 10 segundos maximos
WebDriverWaitElement "//*[@id='formNotas']", 10


     'On Error GoTo reinicio
'reinicio:
'    Exit Sub
 '     Application.Wait (Now + TimeValue("0:00:05"))
'estudiante 01

If ComboBox4.Value = "PRIMER TRIMESTRE" Then
Set lenguaje = Worksheets("sigep").Range("E" & fila)
Set ingles = Worksheets("sigep").Range("F" & fila)
Set sociales = Worksheets("sigep").Range("G" & fila)
Set edufisica = Worksheets("sigep").Range("H" & fila)
Set edumusica = Worksheets("sigep").Range("I" & fila)
Set artes = Worksheets("sigep").Range("J" & fila)
Set matematica = Worksheets("sigep").Range("K" & fila)
Set tecnicageneral = Worksheets("sigep").Range("L" & fila)
Set biogeo = Worksheets("sigep").Range("M" & fila)
Set fisica = Worksheets("sigep").Range("N" & fila)
Set quimica = Worksheets("sigep").Range("O" & fila)
Set filosofia = Worksheets("sigep").Range("P" & fila)
Set valores = Worksheets("sigep").Range("Q" & fila)

manejador.FindElementByXPath("//*[@id='0-6']").SendKeys lenguaje  'pega las notas
manejador.FindElementByXPath("//*[@id='1-6']").SendKeys ingles   'pega las notas
manejador.FindElementByXPath("//*[@id='2-6']").SendKeys sociales   'pega las notas
manejador.FindElementByXPath("//*[@id='3-6']").SendKeys edufisica   'pega las notas
manejador.FindElementByXPath("//*[@id='4-6']").SendKeys edumusica   'pega las notas
manejador.FindElementByXPath("//*[@id='5-6']").SendKeys artes   'pega las notas
manejador.FindElementByXPath("//*[@id='6-6']").SendKeys matematica  'pega las notas
manejador.FindElementByXPath("//*[@id='7-6']").SendKeys tecnicageneral   'pega las notas
manejador.FindElementByXPath("//*[@id='8-6']").SendKeys biogeo   'pega las notas
manejador.FindElementByXPath("//*[@id='9-6']").SendKeys fisica   'pega las notas
manejador.FindElementByXPath("//*[@id='10-6']").SendKeys quimica   'pega las notas
manejador.FindElementByXPath("//*[@id='11-6']").SendKeys filosofia   'pega las notas
manejador.FindElementByXPath("//*[@id='12-6']").SendKeys valores   'pega las notas

Exit Sub
'manejador.FindElementByXPath("//*[@id='formNotas']/div[2]/button[2]").Click   'Guarda cambios
End If


If ComboBox4.Value = "SEGUNDO TRIMESTRE" Then
Set lenguaje = Worksheets("sigep").Range("E" & fila)
Set ingles = Worksheets("sigep").Range("F" & fila)
Set sociales = Worksheets("sigep").Range("G" & fila)
Set edufisica = Worksheets("sigep").Range("H" & fila)
Set edumusica = Worksheets("sigep").Range("I" & fila)
Set artes = Worksheets("sigep").Range("J" & fila)
Set matematica = Worksheets("sigep").Range("K" & fila)
Set tecnicageneral = Worksheets("sigep").Range("L" & fila)
Set biogeo = Worksheets("sigep").Range("M" & fila)
Set fisica = Worksheets("sigep").Range("N" & fila)
Set quimica = Worksheets("sigep").Range("O" & fila)
Set filosofia = Worksheets("sigep").Range("P" & fila)
Set valores = Worksheets("sigep").Range("Q" & fila)

manejador.FindElementByXPath("//*[@id='0-7']").SendKeys lenguaje  'pega las notas
manejador.FindElementByXPath("//*[@id='1-7']").SendKeys ingles   'pega las notas
manejador.FindElementByXPath("//*[@id='2-7']").SendKeys sociales   'pega las notas
manejador.FindElementByXPath("//*[@id='3-7']").SendKeys edufisica   'pega las notas
manejador.FindElementByXPath("//*[@id='4-7']").SendKeys edumusica   'pega las notas
manejador.FindElementByXPath("//*[@id='5-7']").SendKeys artes   'pega las notas
manejador.FindElementByXPath("//*[@id='6-7']").SendKeys matematica  'pega las notas
manejador.FindElementByXPath("//*[@id='7-7']").SendKeys tecnicageneral   'pega las notas
manejador.FindElementByXPath("//*[@id='8-7']").SendKeys biogeo   'pega las notas
manejador.FindElementByXPath("//*[@id='9-7']").SendKeys fisica   'pega las notas
manejador.FindElementByXPath("//*[@id='10-7']").SendKeys quimica   'pega las notas
manejador.FindElementByXPath("//*[@id='11-7']").SendKeys filosofia   'pega las notas
manejador.FindElementByXPath("//*[@id='12-7']").SendKeys valores   'pega las notas
'manejador.FindElementByXPath("//*[@id='formNotas']/div[2]/button[2]").Click   'Guarda cambios
Exit Sub
End If


If ComboBox4.Value = "TERCER TRIMESTRE" Then
Set lenguaje = Worksheets("sigep").Range("E" & fila)
Set ingles = Worksheets("sigep").Range("F" & fila)
Set sociales = Worksheets("sigep").Range("G" & fila)
Set edufisica = Worksheets("sigep").Range("H" & fila)
Set edumusica = Worksheets("sigep").Range("I" & fila)
Set artes = Worksheets("sigep").Range("J" & fila)
Set matematica = Worksheets("sigep").Range("K" & fila)
Set tecnicageneral = Worksheets("sigep").Range("L" & fila)
Set biogeo = Worksheets("sigep").Range("M" & fila)
Set fisica = Worksheets("sigep").Range("N" & fila)
Set quimica = Worksheets("sigep").Range("O" & fila)
Set filosofia = Worksheets("sigep").Range("P" & fila)
Set valores = Worksheets("sigep").Range("Q" & fila)

manejador.FindElementByXPath("//*[@id='0-8']").SendKeys lenguaje  'pega las notas
manejador.FindElementByXPath("//*[@id='1-8']").SendKeys ingles   'pega las notas
manejador.FindElementByXPath("//*[@id='2-8']").SendKeys sociales   'pega las notas
manejador.FindElementByXPath("//*[@id='3-8']").SendKeys edufisica   'pega las notas
manejador.FindElementByXPath("//*[@id='4-8']").SendKeys edumusica   'pega las notas
manejador.FindElementByXPath("//*[@id='5-8']").SendKeys artes   'pega las notas
manejador.FindElementByXPath("//*[@id='6-8']").SendKeys matematica  'pega las notas
manejador.FindElementByXPath("//*[@id='7-8']").SendKeys tecnicageneral   'pega las notas
manejador.FindElementByXPath("//*[@id='8-8']").SendKeys biogeo   'pega las notas
manejador.FindElementByXPath("//*[@id='9-8']").SendKeys fisica   'pega las notas
manejador.FindElementByXPath("//*[@id='10-8']").SendKeys quimica   'pega las notas
manejador.FindElementByXPath("//*[@id='11-8']").SendKeys filosofia   'pega las notas
manejador.FindElementByXPath("//*[@id='12-8']").SendKeys valores   'pega las notas
'manejador.FindElementByXPath("//*[@id='formNotas']/div[2]/button[2]").Click   'Guarda cambios
Exit Sub
End If

End Sub

 

muchas gracias a todos de antemano.

1.png

publicado

Cierra el tema en este foro si has decidido continuar la consulta en el otro y sigue el consejo del Maestro Abraham Valencia para conseguir la mayor ayuda posible, un saludo.

** Es una sugerencia, en ningún momento quiero que se malinterprete  ** 

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

  • 109 ¿Te parecen útiles los tips de las funciones? (ver tema completo)

    1. 1. ¿Te parecen útiles los tips de las funciones?


      • No
      • Ni me he fijado en ellos

  • Ayúdanos a mejorar la comunidad

    • Donaciones recibidas este mes: 0.00 EUR
      Objetivo: 130.00 EUR
  • Archivos

  • Estadísticas de descargas

    • Archivos
      188
    • Comentarios
      98
    • Revisiones
      29

    Más información sobre "Cambios en el Control Horario"
    Última descarga
    Por pegones1

    4    1

  • Crear macros Excel

  • Mensajes

    • Hola, veo que tienes 365, así que esta forma funcionará   Almacen.xlsx
    • Buenos días  @LeandroA espero estes bien Tengo un caso idéntico al planteado en la siguiente pregunta: Sin embargo, a diferencia de quien planteo originalmente la pregunta al correr el código no obtengo ningún resultado podrían ayudarme a resolver este inconveniente y que al hacer click en el Botón Guardar (CommandButton3) del Formulario RCS (frmrcs) el archivo pdf quede configurado con orientación vertical, márgenes superior, inferior, derecho e izquierdo = 1 y en página tamaño carta. Si acaso influye uso Microsoft Excel LTSC MSO (versión 2209 Compilación16.0.1.15629.20200) de 64 bits Mucho le sabre agradecer la ayuda que me pueda dar  RCS PRUEBA - copia.xlsm
    • @JSDJSDCon gusto mi estimado Para la opción 1: Sub Surtirhastadondealcanse() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets(1) Dim filaInicio As Integer: filaInicio = 4 Dim filaFin As Integer: filaFin = 7 Dim colInventario As Integer: colInventario = 2 Dim colSolicitudesInicio As Integer: colSolicitudesInicio = 4 ' Columna C Dim colResultadoInicio As Integer: colResultadoInicio = 9 ' Columna I Dim colTotalSurtido As Integer: colTotalSurtido = 12 ' Columna L Dim colFinalInventario As Integer: colFinalInventario = 13 ' Columna M Dim numClientes As Integer: numClientes = 3 Dim fila As Integer, i As Integer For fila = filaInicio To filaFin Dim inventario As Double inventario = Val(ws.Cells(fila, colInventario).Value) Dim solicitudes(1 To 3) As Double Dim surtido(1 To 3) As Variant Dim totalSurtido As Double: totalSurtido = 0 ' Leer solicitudes For i = 1 To numClientes If IsNumeric(ws.Cells(fila, colSolicitudesInicio + i - 1).Value) Then solicitudes(i) = CDbl(ws.Cells(fila, colSolicitudesInicio + i - 1).Value) Else solicitudes(i) = 0 End If surtido(i) = "POR FALTA STOCK" Next i ' Surtir de acuerdo al inventario disponible For i = 1 To numClientes If solicitudes(i) > 0 Then If inventario >= solicitudes(i) Then surtido(i) = solicitudes(i) inventario = inventario - solicitudes(i) totalSurtido = totalSurtido + solicitudes(i) ElseIf inventario > 0 Then surtido(i) = inventario totalSurtido = totalSurtido + inventario inventario = 0 Else surtido(i) = "POR FALTA STOCK" End If End If Next i ' Escribir resultados en las columnas correspondientes para cada cliente For i = 1 To numClientes With ws.Cells(fila, colResultadoInicio + i - 1) If surtido(i) = "POR FALTA STOCK" Then .Value = surtido(i) .Font.Color = vbRed Else .Value = surtido(i) .Font.Color = vbBlack End If End With Next i ' Escribir total surtido y existencia final ws.Cells(fila, colTotalSurtido).Value = totalSurtido ws.Cells(fila, colFinalInventario).Value = inventario Next fila MsgBox "Resultado surtido cargado con éxito...", vbInformation End Sub Para la opción 2:   Sub surtirenpartesiguales() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets(1) Dim filaInicio As Integer: filaInicio = 13 Dim filaFin As Integer: filaFin = 16 Dim colInventario As Integer: colInventario = 2 Dim colSolicitudesInicio As Integer: colSolicitudesInicio = 4 ' Columna C Dim colResultadoInicio As Integer: colResultadoInicio = 9 ' Columna I Dim colTotalSurtido As Integer: colTotalSurtido = 12 ' Columna L Dim colFinalInventario As Integer: colFinalInventario = 13 ' Columna M Dim numClientes As Integer: numClientes = 3 Dim fila As Integer, i As Integer For fila = filaInicio To filaFin Dim inventario As Double inventario = Val(ws.Cells(fila, colInventario).Value) Dim solicitudes(1 To 3) As Double Dim surtido(1 To 3) As Variant Dim totalSurtido As Double: totalSurtido = 0 Dim totalPedido As Double: totalPedido = 0 ' Leer solicitudes For i = 1 To numClientes If IsNumeric(ws.Cells(fila, colSolicitudesInicio + i - 1).Value) Then solicitudes(i) = CDbl(ws.Cells(fila, colSolicitudesInicio + i - 1).Value) totalPedido = totalPedido + solicitudes(i) Else solicitudes(i) = 0 End If surtido(i) = 0 Next i ' Si hay suficiente inventario, surtir lo que el cliente pide If inventario >= totalPedido Then For i = 1 To numClientes If solicitudes(i) > 0 And inventario >= solicitudes(i) Then surtido(i) = solicitudes(i) inventario = inventario - solicitudes(i) totalSurtido = totalSurtido + solicitudes(i) End If Next i Else ' Reparto base igualitario Dim baseSurtido As Long baseSurtido = Int(inventario / numClientes) For i = 1 To numClientes If solicitudes(i) > 0 Then If solicitudes(i) <= baseSurtido Then surtido(i) = solicitudes(i) inventario = inventario - solicitudes(i) totalSurtido = totalSurtido + solicitudes(i) Else surtido(i) = baseSurtido inventario = inventario - baseSurtido totalSurtido = totalSurtido + baseSurtido End If End If Next i ' Repartir sobrante restante uno por uno, respetando lo pedido Do While inventario > 0 For i = 1 To numClientes If surtido(i) < solicitudes(i) Then surtido(i) = surtido(i) + 1 totalSurtido = totalSurtido + 1 inventario = inventario - 1 If inventario = 0 Then Exit For End If Next i Loop End If ' Escribir resultados en las columnas correspondientes para cada cliente For i = 1 To numClientes With ws.Cells(fila, colResultadoInicio + i - 1) If surtido(i) = 0 Then .Value = "POR FALTA STOCK" .Font.Color = vbRed Else .Value = surtido(i) .Font.Color = vbBlack End If End With Next i ' Escribir total surtido y existencia final ws.Cells(fila, colTotalSurtido).Value = totalSurtido ws.Cells(fila, colFinalInventario).Value = inventario Next fila MsgBox "Resultado surtido cargado con éxito...", vbInformation End Sub Saludos, Diego
    • Buenos dias.  Estoy trabajando en una hoja para poder llevar un control de un pequeño almacén.  Tengo un pedido con varias líneas y "lotes" y necesito sacar las ubicaciones que coincidan con la referencia y lote que pone en el pedido. El problema viene cuando tengo la misma referencia y mismo lote en ubicaciones diferentes y necesito sacar la información en columnas diferentes. No se si  me he explicado bien, pero creo que con el ejemplo adjunto se entiende mejor. Agradecería mucho si me pudieran ayudar  Libro1.xlsx
    • Exelente solución mil gracias 
  • Visualizado recientemente

    • No hay usuarios registrado para ver esta página.
×
×
  • Crear nuevo...

Información importante

Echa un vistazo a nuestra política de cookies para ayudarte a tener una mejor experiencia de navegación. Puedes ajustar aquí la configuración. Pulsa el botón Aceptar, si estás de acuerdo.