How to convert column of numbers to text separated by comma in set of four
Simple VBA macro to transpose a single column to multiple columns
I commented every step, so its easy to adjust the macro to your personal needs.
You can choose your data column and how many columns you want after transposing
- Open Excel and VBA editor with Alt+F11
- On the left pane, paste the code under the sheet where your data is placed
- Modify the first two lines according to your needs
- Execute the macro with F5
Const strCol = "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