Macro VBA simples para transpor uma única coluna para várias colunas
Comenteitodasasetapas,porissoéfácilajustaramacroàssuasnecessidadespessoais.
Vocêpodeescolhersuacolunadedadosequantascolunasdesejadepoisdetranspor
- AbraoeditorExceleVBAcomAlteF11
- Nopainelesquerdo,coleocódigonafolhaondeseusdadossãocolocados
- Modifiqueasduasprimeiraslinhasdeacordocomsuasnecessidades
- ExecuteamacrocomF5
ConststrCol="B" '## select the column with your data
Const iTrans = 4 '## select how many columns you want after transposing
Sub transposeColumn()
'## search the last row to know how many cells we have to iterate through
iLastrow = Range(strCol & ActiveSheet.Rows.Count).End(xlUp).Row
iCol = Range(strCol & 1).Column
'## begin to loop through the chosen column
'## Cause we delete cells on every loop, we need to divide the loop counter
'## And since the division result isn't an integer, we have to round up
For i = 1 To WorksheetFunction.RoundUp(iLastrow / iTrans, 0)
'## set the source and target range for easier access later
Set rngSrc = Range(Cells(i + 1, iCol), Cells(i + iTrans - 1, iCol))
Set rngTrg = Range(Cells(i, iCol + 1), Cells(i, iCol + iTrans - 1))
'## set the format of target range to text
rngTrg.NumberFormat = "@"
'## copy and paste the values, the trick is to use transpose
rngSrc.Copy
rngTrg.PasteSpecial Transpose:=True
'## delete all cells which we have just transposed
rngSrc.Delete shift:=xlUp
Next i
End Sub