Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations danielledunham on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically Sort New Data in Excel 1

Status
Not open for further replies.

kabushnell

Technical User
Joined
Jun 4, 2003
Messages
81
Location
US
Is there a way to have Excel automatically resort a sheet when new information is added? I have a spreadsheet that is sorted by an ID number and I want Excel to sort automatically after the new ID and Name have been enetered.
 
...make sure that macro security is not set to high (tools>macro>security)

start the macro recorder it will default to macro1 for a name...

go through the steps of sorting your data.

stop the macro recorder

press alt+F11 to view the macro editor and the code that it just created,

copy the text between the "Sub macro1 ()" and "End Sub" lines.

then dbl click in the sheets' name ("sheet?") in the left "vba project window", and in the right window, click the left drop down to select "worksheet" then the right drop down to select the "change" event...

...you will see an empty sub created that looks like this.

Private Sub Worksheet_Change(ByVal Target As Range)

'paste your text here

End Sub


....alt+F11 to return to the sheet.

Now when the value of any cell changes...the sheet will run the sort





 
Thanks, that works. One other question? Is there a way to have it only sort when a cell inColumn A changes? Not when any of the other cells change.
 
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
.....etc

Regards
Ken...........


----------------------------------------------------------------------------
[peace]It's easier to beg forgiveness than ask permission[2thumbsup]

----------------------------------------------------------------------------
 
KENWRIGHT,..

depending on data entry navigation,..that alone may not work,

stay tuned... I'll put something together to account for [tab] or [enter] after user input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top