Creating a sortable column
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. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
Creating a sortable column
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 -- Regards, Tom Ogilvy "rsine" wrote in message ... 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. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
All times are GMT +1. The time now is 11:21 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com