Hello! I am new to Excel VBA and need major help for my code.
Please refer to my picture and the excel sheet data below as reference.
GIVEN:
A 4-column list of data points.
There are an arbitrary number of sets, defined by an existing number in column A, followed by blank cells in A but "x,y,z" points in B, C, D.
Each set contains an arbitrary amount of points.
OBJECTIVE:
I'd like to parse the single columns into multiple columns, but each column contains an arbitrary number of points.
The picture provided shows what I'd like to do, please look at that for a clearer picture.
PROBLEM:
My code is not working, it only took 2 cells and placed it to the side.
Is there a problem with the loop? I can't seem to figure it out...
Please help! Thank you, much appreciated!
row = 2 'start at row 2
col = 2 'start at column B
Do While IsEmpty(Cells(row, 2)) = False 'Keep running code if 2nd column is not empty
If IsEmpty(Cells(row, 1)) = False Then 'If column A is not empty, move over to new column
Cells(row, 2).Select
Selection.Cut Destination:=Cells(row, col + 2) 'Take column B and move over 2 columns
Cells(row, 3).Select
Selection.Cut Destination:=Cells(row, col + 3) 'Take column C and move over 2 columns
col = col + 2 'Move across 2 columns
Else
Cells(row, 2).Select
Selection.Cut Destination:=Cells(row, col + 2) 'Take row and move to the current column
Cells(row, 3).Select
Selection.Cut Destination:=Cells(row, col + 3) 'Take column C and move over 2 columns
col = col + 2 'Move across 2 columns+ 1, col))
row = row + 1 'Move down a row
End If
Loop
End Sub
ColumnMove.png
Bookmarks