Creating a sortable column

  • Thread starter Thread starter rsine
  • Start date Start date
R

rsine

I would like to create a macro that would insert a column into a
spreadsheet which I can then sort by. Not being familar with creating
macros, I am looking for any guidance on how to get started. What the
macro needs to do is as follows:

1) insert a column into the active spreadsheet as the
first column.

2) starting with the active cell in this newly inserted
column, populate it with A1,B1,C1,A2,B2,C2,A3,B3,C3,
and so on until there is no more data in the second
column.

I'll also need to know how to save this macro so that I can use it over
again.

Any help on this is greatly appreciated.
 
Sub SortMyData()
Dim rng As Range, i As Long, J As Long
Dim cell As Range
Columns(3).Insert
Cells(1, 3).Value = "HeaderC"
Set rng = Range(Cells(2, 2), _
Cells(Rows.Count, 2).End(xlUp))
i = 1
J = 64
For Each cell In rng
J = J + 1
cell.Offset(0, 1).Value = Chr(J) & i
If J = 67 Then
J = 64: i = i + 1
End If
Next
Cells(1, 3).CurrentRegion.Sort _
Key1:=Cells(1, 3), Order1:=xlAscending, _
Header:=xlYes

Columns(3).Delete
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