Alphabetize every second row

kdr

New Member
Joined
Nov 23, 2010
Messages
17
I have a rather large spreadsheet of ticket/certifications and expiries. I'd like to alphabetize the employees without mixing up their information; their names are in every second row with certification dates following, and on the row below their names underneith their certification dates are the expiries:

eg.

SMITH, John Jan 1, 2009
Expiry Jan 1, 2012
DOE, Jane March 2, 2009
Expiry March 2, 2012

And so on. The second rows all say "Expiry" so I don't want it to sort those too.

Can this be done?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
kdr,


Sample data before the macro, with Smith, John Jan 1, 2009 in cell A1:


Excel Workbook
A
1Smith, John Jan 1, 2009
2Expiry Jan 1, 2012
3Doe, Jane March 2, 2009
4Expiry March 2, 2012
5
Sheet1





After the macro:


Excel Workbook
A
1SMITH, John Jan 1, 2009
2Expiry Jan 1, 2012
3DOE, Jane March 2, 2009
4Expiry March 2, 2012
5
Sheet1





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub MakeUpper()
' hiker95, 01/28/2011
' http://www.mrexcel.com/forum/showthread.php?t=524737
Dim c As Range
Application.ScreenUpdating = False
For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
  If Left(c, 6) <> "Expiry" Then
    c = UCase(Left(c, Application.Find(",", c, 1) - 1)) & Right(c, Len(c) - Application.Find(",", c, 1) + 1)
  End If
Next
Application.ScreenUpdating = True
End Sub


Then run the MakeUpper macro.
 
Upvote 0
Oh, sorry! The name and 'expiry' are in column A2 and A3. The certificates and dates follow in columns B2 and B3 through AF2 and AF3. Can it be done without macros? (A little tinkering and I think I can figure it out if not)
 
Upvote 0
kdr,

I am not sure if you can do what you want with a formula.


Sample data before the updated macro:


Excel Workbook
AB
1
2Smith, JohnJan 1, 2009
3ExpiryJan 1, 2012
4Doe, JaneMar 2, 2009
5ExpiryMar 2, 2012
6
Sheet1





After the updated macro:


Excel Workbook
AB
1
2SMITH, JohnJan 1, 2009
3ExpiryJan 1, 2012
4DOE, JaneMar 2, 2009
5ExpiryMar 2, 2012
6
Sheet1





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


Code:
Option Explicit
Sub MakeUpperV2()
' hiker95, 01/28/2011
' http://www.mrexcel.com/forum/showthread.php?t=524737
Dim c As Range
Application.ScreenUpdating = False
For Each c In Range("A2", Range("A" & Rows.Count).End(xlUp))
  If Left(c, 6) <> "Expiry" Then
    c = UCase(Left(c, Application.Find(",", c, 1) - 1)) & Right(c, Len(c) - Application.Find(",", c, 1) + 1)
  End If
Next
Application.ScreenUpdating = True
End Sub


Then run the MakeUpperV2 macro.
 
Upvote 0
hiker95: I don't see your version alphabetizing...just capitalizing their last names? Jane Doe's name should be above John Smith's and her march dates should move along with her...
 
Upvote 0
kdr,

Now I understand.


Sample data before the macro (accounting for/calculating the last used column in your dataset):


Excel Workbook
AB
1
2SMITH, JohnJan 1, 2009
3ExpiryJan 1, 2012
4DOE, JaneMar 2, 2009
5ExpiryMar 2, 2012
6
Sheet1





Then we insert a column and create unique identifiers for each name:


Excel Workbook
ABC
1
2SMITH, John2SMITH, JohnJan 1, 2009
3SMITH, John3ExpiryJan 1, 2012
4DOE, Jane4DOE, JaneMar 2, 2009
5DOE, Jane5ExpiryMar 2, 2012
6
Sheet1





Then we sort the entire dataset by column A:


Excel Workbook
ABC
1
2DOE, Jane4DOE, JaneMar 2, 2009
3DOE, Jane5ExpiryMar 2, 2012
4SMITH, John2SMITH, JohnJan 1, 2009
5SMITH, John3ExpiryJan 1, 2012
6
Sheet1





Then we delete column A, and we have:


Excel Workbook
AB
1
2DOE, JaneMar 2, 2009
3ExpiryMar 2, 2012
4SMITH, JohnJan 1, 2009
5ExpiryJan 1, 2012
6
Sheet1





Is this what you are looking for?
 
Upvote 0
kdr,

Per the latest screenshots:


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub ReorgData()
' hiker95, 01/28/2011
' http://www.mrexcel.com/forum/showthread.php?t=524737
Dim LR As Long, LC As Long, a As Long
Application.ScreenUpdating = False
Columns(1).Insert
LR = Cells(Rows.Count, 2).End(xlUp).Row
LC = Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
For a = 2 To LR Step 2
  Range("A" & a).FormulaR1C1 = "=RC[1]&ROW()"
  Range("A" & a + 1).FormulaR1C1 = "=R[-1]C[1]&ROW()"
  With Range("A" & a & ":A" & a + 1)
    .Value = .Value
  End With
Next a
Range(Cells(2, 1), Cells(LR, LC)).Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
  OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
Columns(1).Delete
Application.ScreenUpdating = True
End Sub


Then run the ReorgData macro.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top