Saltar al contenido

Seleccionar "x" fila y "x" rangos de la fila de una hoja y pegarlos en otra hoja


Recommended Posts

publicado

Hola a todos soy nuevo en este foro, este es mi problema tengo que crear la forma de que con un formulario el usuario introduzca en un TextBox numero de gafet y al dar clic al botón este busque y seleccione la fila donde encontró el dato y ciertos rangos sean copiados y pegados en otra hoja de Excel 2003 lo que yo hice fue crear dos hojas dentro de mi libro hoja1 se llama “bd” , hoja2 se llama “reporte”, en bd tengo una tabla con los campos

gafet nomina nombre apellido proyecto

en la hoja “reporte” se peguen gafet nomina nombre apellido , nombre y apellido juntos y la fecha y hora en cuanto caiga el dato.

Lo que yo hice fue una internas con su botón buscar este lo busca y muestra los campos que yo quier ver y cree un botón enviar el cual se envían los datos a otra tabla en otra hoja.

Este es el código:

' boton buscar

Private Sub CommandButton1_Click()

Dim id_gafet As Integer

Dim idBuscar As Integer

Dim fila As Integer

fila = 1

id_gafet = TextBoxBusca '''

Do While idBuscar <> id_gafet

fila = fila + 1

idBuscar = Range("A" & fila).Value

If idBuscar = Empty Then

MsgBox "No se encontro dato"

Exit Do

End If

Loop

Dim nom, ap As String

Dim num_gafet, num_nomina As Integer

nom = Range("C" & fila).Value

ap = Range("D" & fila).Value

TextBox2 = nom & " " & ap

TextBox3 = Range("A" & fila).Value

TextBox4 = Range("B" & fila).Value

TextBoxBusca.SetFocus

''''''''''''''''''''''''''''''''''''''''''

End Sub

' boton enviar

Private Sub CommandButton2_Click()

ActiveSheet.Protect DrawingObjects:=False, Contents:=False, Scenarios:=False

ActiveWorkbook.Protect Structure:=False, Windows:=False

Sheets("REPORTE").Activate

If TextBox2 = "" Or TextBox3 = "" Or TextBox4 = "" Then

MsgBox "Esta dejando campos requeridos vacion favor complete", vbExclamation, "REPORTE"

TextBox3.SetFocus

Else

Range("A" & Cells.Rows.Count).End(xlUp).Offset(1).Select

ActiveCell = TextBox3.Value

ActiveCell.Offset(0, 1) = TextBox4.Value

ActiveCell.Offset(0, 2) = TextBox2.Value

'ActiveCell.Offset(0, 3) = TextBox2.Value

MsgBox "Empleado ingresado exitosamente", vbInformation, "ServiCal"

'TextBox3 = ""

TextBox4 = ""

TextBox2 = ""

TextBox2.SetFocus

End If

' codigo para colocar la hora un la columna deseada

Dim x As Long, y As Long

With ActiveSheet

x = .Cells(.Rows.Count, "D").End(xlUp).Row + 1

y = .Cells(.Rows.Count, "A").End(xlUp).Row

If x <= y Then

.Range(.Cells(x, "D"), .Cells(y, "D")) = _

DateSerial(Year(Date), Month(Date), Day(Date))

End If

End With

' codigo para colocar hora automatica

Range("D1").Select

While ActiveCell <> ""

ActiveCell.Offset(0, 1).Select

While ActiveCell <> ""

ActiveCell.Offset(1, 0).Select

Wend

ActiveCell.Value = Format(Now, "hh:mm:ss")

ActiveCell.Offset(0, -1).Select

ActiveCell.Offset(1, 0).Select

Wend

Sheets("BD").Activate

End Sub

Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

If KeyAscii < 47 Or KeyAscii > 57 Then KeyAscii = 0

End Sub

Private Sub TextBox3_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

If KeyAscii < 45 Or KeyAscii > 57 Then KeyAscii = 0

End Sub

Private Sub TextBox4_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

If KeyAscii < 47 Or KeyAscii > 57 Then KeyAscii = 0

End Sub

' boton para salir

Private Sub CommandButton3_Click()

End '--> Liquida TODAS las variables y/o similares de la memoria

Hide '--> Solo oculta el userform, mas no lo descarga de la memoria

Unload Me '--> Descarga el userform de la memoria

End Sub

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.