Data Split and sort problem

  • Thread starter Thread starter joecrabtree
  • Start date Start date
J

joecrabtree

To all,

I have a list of data in column A: eg:

L1
L2
M2
M7
H7
H10
L6
L8
M6
M99

etc

I want to be able to split the data in column A into three columns:

All the data starting with 'L' in column B, i.e. L1,L2, L6,L8
All the data starting with 'M' in column C i.e., M2, M7, M6
All the data starting with 'H' in column D i.e. H10

I would like the data to be sorted in each column. Can this be done
using a macro?

Thanks for all your help in advance,

Kind Regards

Joseph Crabtree
 
Perfect. Many Thanks.

You can sort the column before then add this to code it will do them in
order. This assumes there are no blanks in column A

Sub main()
Dim myRow, bRow, cRow, dRow As Integer
bRow = 1
cRow = 1
dRow = 1
myRow = 1

Do Until Cells(myRow, 1) = ""
If Left(Cells(myRow, 1), 1) = "L" Then
Cells(bRow, 2) = Cells(myRow, 1)
bRow = bRow + 1
End If

If Left(Cells(myRow, 1), 1) = "M" Then
Cells(cRow, 3) = Cells(myRow, 1)
cRow = cRow + 1
End If

If Left(Cells(myRow, 1), 1) = "H" Then
Cells(dRow, 4) = Cells(myRow, 1)
dRow = dRow + 1
End If

myRow = myRow + 1
Loop

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top