![]() |
VBA sort records occupying 2 rows each
Help! VBA code to sort records where a record exists on two consecutiv rows. There are no blank rows between records & the 1st record start on line 2. For Example: Row 2: Doe John 123 South Street Summerville, TX 76625 Row 3: (903)752-4813 Row 4: Johnson Jack 1849 Hwy 200 Johnsonville, TX 76362 Row 5: (903)238-5849 The number of records to sort are always different since when record are added, they will be sorted in. Usually we will be sorting usin column A & maybe column B. Thanks for any & all help. mikebur -- mikebur ----------------------------------------------------------------------- mikeburg's Profile: http://www.excelforum.com/member.php...fo&userid=2458 View this thread: http://www.excelforum.com/showthread.php?threadid=46688 |
VBA sort records occupying 2 rows each
Mike,
Try the macro below. HTH, Bernie MS Excel MVP Sub Macro1() Dim myRow As Long Columns("A:B").Insert Range("A1").Value = "Sort1" Range("B1").Value = "Sort2" Range("A2").FormulaR1C1 = "=RC[2]" Range("A3").FormulaR1C1 = "=R[-1]C[2]" Range("A2:A3").Copy myRow = Cells(Rows.Count, 3).End(xlUp).Row If myRow Mod 2 < 1 Then myRow = myRow + 1 Range("A2:B" & myRow).Select ActiveSheet.Paste With Columns("A:B") .Copy .PasteSpecial Paste:=xlPasteValues End With Range("A3").CurrentRegion.Sort Key1:=Range("A2"), Order1:=xlAscending, _ Key2:=Range("B2"), Order2:=xlAscending, Header:=xlYes, _ Orientation:=xlTopToBottom, DataOption1:=xlSortNormal Columns("A:B").Delete End Sub "mikeburg" wrote in message ... Help! VBA code to sort records where a record exists on two consecutive rows. There are no blank rows between records & the 1st record starts on line 2. For Example: Row 2: Doe John 123 South Street Summerville, TX 76625 Row 3: (903)752-4813 Row 4: Johnson Jack 1849 Hwy 200 Johnsonville, TX 76362 Row 5: (903)238-5849 The number of records to sort are always different since when records are added, they will be sorted in. Usually we will be sorting using column A & maybe column B. Thanks for any & all help. mikeburg -- mikeburg ------------------------------------------------------------------------ mikeburg's Profile: http://www.excelforum.com/member.php...o&userid=24581 View this thread: http://www.excelforum.com/showthread...hreadid=466882 |
VBA sort records occupying 2 rows each
Thank you. mikebur -- mikebur ----------------------------------------------------------------------- mikeburg's Profile: http://www.excelforum.com/member.php...fo&userid=2458 View this thread: http://www.excelforum.com/showthread.php?threadid=46688 |
All times are GMT +1. The time now is 12:05 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com