VBA: Sort Range after New Data

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
831
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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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