VBA: Sort Range after New Data

bamaisgreat

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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,226,693
Messages
6,192,460
Members
453,725
Latest member
cvsdatreas

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