VBA: Sort Range after New Data

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
823
Office Version
  1. 365
Platform
  1. Windows
Is it possible to sort the range a to z after the code below.

Code:
Private Sub CommandButton1_Click()
Dim newEntry As Variant, rws As Long, adr As String
newEntry = UserForm4.TextBox1.Value
rws = Range("Grades").Rows.Count
Range("Grades").Cells(1, 1).Offset(rws, _
    0).Value = newEntry


Unload Me
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Maybe this:
Code:
[FONT=Lucida Console][COLOR=Royalblue]Dim[/COLOR] newEntry [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Variant[/COLOR], rws [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Long[/COLOR], adr [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]String[/COLOR]
newEntry = UserForm4.TextBox1.Value

[COLOR=Royalblue]With[/COLOR] Range([COLOR=Darkcyan]"Grades"[/COLOR])
    rws = .Rows.count
    .Cells([COLOR=Brown]1[/COLOR], [COLOR=Brown]1[/COLOR]).Offset(rws, [COLOR=Brown]0[/COLOR]).Value = newEntry
    .Resize(rws + [COLOR=Brown]1[/COLOR]).Sort Key1:=.Cells([COLOR=Brown]1[/COLOR]), Order1:=xlAscending, Header:=xlNo
[COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]With[/COLOR]
Unload [COLOR=Royalblue]Me[/COLOR][/FONT]
 
Upvote 0

Forum statistics

Threads
1,215,456
Messages
6,124,939
Members
449,197
Latest member
k_bs

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