Still teaching myself VBA but I have a problem and have no idea how to tackle it.

I have a bunch of 3D coordinate (X,Y,Z) barcodes scanned into excel and need them sorted into specific columns based on the direction represented by the first letter (X,Y,Z) in the barcode. A set of data has an X, Y, Z coordinate and is bookmarked by "END" scans.The scans come in like below and the user can scan in any order as long as he bookmarks each data set with an "END" scan.

X1234
Y3242
Z2342
END
Z6546
X654
Y5435
END
Y6544
X65445
Z5335
END

I need a macro that can sort the scans into this format:
X1234 Y3242 Z2342
X654 Y5435 Z6546
X65445 Y6544 Z5335

Any help would be much appreciated. Thanks in advance.