VBA - Union of two non-adjacent ranges and transposed paste into another sheet

Asked

Viewed 85 times

0

In order to minimize the number of selections for a spreadsheet in an iteration of 75000 records, I am trying to merge two non-adjacent ranges (2 separate columns, a total of 10 rows) in a spreadsheet whose values will be pasted in another spreadsheet transposed and adjacent, in a table (1 row and 10 columns).

Dim Vpo As Worksheet
Dim Resultados As Worksheet
Dim DadosResultados As Range

Set Vpo = Sheets("VPO - ATI")
Set Resultados = Sheets("Resultados Individuais")

Set DadosResultados = Appplication.Union(Vpo.Range("I9:I10"), _
    Vpo.Range("Q17:Q24"))

Resultados.Cells(Contagem, 9).Value = Application _
    .WorksheetFunction.Transpose(DadosResultados)

This method is not proving useful, since although there is no error of execution, the values are not being pasted.

I would like to help to try to better understand the problem.

Snapping that copy and paste twice, one for each column, works well, but the run time for the amount of records is very large.

Below is the code mentioned in the previous paragraph:

Resultados.Cells(11, 9).Value = Vpo.Range("I9").Value
Resultados.Cells(11, 10).Value = Vpo.Range("I10").Value

Vpo.Range("Q17:Q24").Copy

Resultados.Range("I11").PasteSpecial Transpose:=True, Paste:=xlValues _
    SkipBlanks:=False
  • What is the value of Contagem in Resultados.Cells(Contagem, 9).Value?

  • Starts at row 11 and ends at the total row count of the consulted table.

  • But when Contagem is incremented in your code? You don’t actually need to increment and use the count...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.