VBA Excel Code

Asked

Viewed 32 times

1

Fala Galera!

I need to create a code that copies a horizontal list of a sheet and paste it into another sheet in vertical form. Each time the command is executed, it must skip the line to copy the next information. Someone could help me?

  • There is a practical example of how this copy would look with an example information ? What code has developed so far ?

1 answer

1

Here is an example, just choose the Sheet where you want to make the change, column and source and destination line and number of elements:

Sub Horizontaltovertical()

Set Source = ThisWorkbook.Sheets("Sheet1")
Set dest = ThisWorkbook.Sheets("Sheet1")

Const numeroElementos = 10

Const linhaInicialOrigem = 1
Const columaInicialOrigem = 1

Const linhaInicialDestino = 2
Const colunaInicialDestino = 2

Dim X As Integer
Dim Y As Integer


    For Y = 0 To numeroElementos
        dest.Cells(colunaInicialDestino, Y + linhaInicialDestino).Value = Source.Cells((X * stepSize) + (Y + linhaInicialOrigem), columaInicialOrigem)
    Next Y

End Sub

Browser other questions tagged

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