Sorting Rows in ascending order based on column B - with VBA

tyrese213

New Member
Joined
Aug 24, 2007
Messages
10
Hi,

Question, I am trying to sort full rows of data with vba based on the Value of Column B. I have 1500 rows. each of these rows have a number in column B.

Column B is a number field and the rest of the columns are text fields...

I have to do this each day for 4 sheets before I run some other vba code. (that imports into another spreadsheet but before I import the data i want it automatically sorted) what is the correct syntax for this.. thankyou all..
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Let say your data start from row 2. Try this code. Change the Range("B2") to your start row.

Code:
Sub Test()
Range("B2").CurrentRegion.Select
    Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
End Sub
 
Upvote 0
Don't select/activate

Code:
Sub test()
Range("b2").CurrentRegion.Sort key1:=Range("b2"), order1:=xlAscending, header:=xlGuess
End Sub
 
Upvote 0
Thanks Jindon, you really a good teacher.
Don't select/activate

Code:
Sub test()
Range("b2").CurrentRegion.Sort key1:=ws.Range("b2"), order1:=xlAscending, header:=xlGuess
End Sub
 
Upvote 0
jindon,

Thanks for taking the time to share your knowledge. I really appreciate being able to find answers here so quickly.

Jeff
 
Upvote 0
Hi,

I have 14 columns named part_1, part_2 upto part_14. There are nearly 800 rows in the sheet. I want to arrange the data of all the rows in ascending(alphabetic) order. For eg. if for row 1 part_1 = a, part_2 =c, part_3 = b and for row 2 part_1 = x, part_2 =z, part_3 = y.

Then, the output should be:
for row 1 part_1 = a, part_2 =b, part_3 = c and for row 2 part_1 = x, part_2 =y, part_3 = z.

Can anyone help me?
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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