Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
Uso de VBA para copiar datos de una hoja de cálculo a una nueva según los valores de las celdas

Estoy empezando con VBA y estoy tratando de jugar un poco para ver qué puedo hacer.

Estoy tratando de escribir una macro que genere automáticamente un informe a partir de una subsección de datos en una hoja de trabajo principal.

Solo quiero copiar filas donde el valor en la Columna D es "China" Y el valor en la Columna H es "HS" . Además, solo busco copiar datos de una selección de filas (A:C,E,F,G,I,Q,R,AF:AH,AN,AP,AQ).

Hasta ahora estoy haciendo esto por:

  1. Creando una nueva hoja
  2. Copiar la fila del título
  3. Buscar datos relevantes y copiar/pegar en la nueva hoja

Siguiendo algunas respuestas que encontré aquí y en otros foros, reuní lo siguiente. La mitad superior funciona bien (generando la hoja y copiando la fila del título), pero la parte importante principal no.

Perdóname si este es un trabajo de Frankenstein, soy nuevo aquí pero estoy tratando de aprender.

 Option Explicit Sub GenerateHSReport() 'Generating the sheet' Sheets.Add(Count:=1).Name = "HS Report " & Format(Date, "DD-MM-YY") 'Adding the title row' Sheets("SANBI - all bids").Range("A4:C4,E4,F4,G4,I4,Q4,R4,AF4:AH4,AN4,AP4,AQ4").Copy Sheets("HS Report " & Format(Date, "DD-MM-YY")).Activate Range("A1").Select ActiveSheet.Paste 'Copying the HS data' Dim srchtrm As String Dim rng As Range, destRow As Long Dim shtSrc As Worksheet, shtDest As Worksheet Dim c As Range Dim i As Integer With Application .ScreenUpdating = False .DisplayStatusBar = False .Calculation = xlCalculationManual .EnableEvents = False End With Set shtSrc = Sheets("SANBI - all bids") Set shtDest = Sheets("HS Report " & Format(Date, "DD-MM-YY")) Set c = Range("A5:C5,E5,F5,G5,I5,Q5,R5,AF5:AH5,AN5,AP5,AQ5") destRow = 2 Set rng = Application.Intersect(shtSrc.Range("D:D, H:H"), shtSrc.UsedRange) For Each c In rng.Cells If c.Value = "HS" And c.Value = "China" Then c.Copy shtDest.Cells(destRow, 2) destRow = destRow + 1 End If Next With Application .ScreenUpdating = True .DisplayStatusBar = True .Calculation = xlCalculationAutomatic .EnableEvents = True End With Application.CutCopyMode = False End Sub
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Estoy en mi teléfono, así que no puedo probar la televisión en este momento, pero debería guiarlo en la dirección correcta

 Set rng = shtSrc.UsedRange Dim row as range For Each row In rng.rows If row.columns("h").value = "HS" And row.columns("d").value = "China" Then shtDest.Cells(destRow, 2).value = Row.columns("b").value destRow = destRow + 1 End If Next

Haciendo algo así, entiendes la idea, de nuevo, no está probado

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!