View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Michael Michael is offline
external usenet poster
 
Posts: 791
Default sort excel when the workbook is opened

Excellent, although I had to paste all 5 lines for it to work. Thank you very
much

"Mike" wrote:

Michael,

You've put the code in the wrong place. Do this.
open workbook and click TOOLS - MACRO - VISUAL BASIC EDITOR
Double click THIS WORKBOOK
In the drop down select WORKBOOK
In the other dropdown (If it doesn't come up automatically) Select OPEN
Paste the code in there and save. The first and last lines are created
automatically so be careful to only paste the middle 3 lines.

Mike


"Michael" wrote:

Thanks, I have pasted that code by clicking view code on sheet1 of my
worksheet and then pasting the code you gave me and it works if I select the
macro and run it but I want it to be sorted automatically without having to
press anything. Have I done something wrong?

"Mike" wrote:

This will sort column A on sheet 1 every time the workbook is opened. You
will have to change the worksheet name and maybe ascendind/descending

Private Sub Workbook_Open()
Worksheets("Sheet1").Select
Cells.Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending
End Sub

Mike
"Michael" wrote:

Hi, could anyone tell me how to automatically sort a worksheet when the
workbook is opened please?
ie I have data in column A in sheet1 on workbook1 that is linked to
workbook2. When I open workbook1 the data in workbook2 may have been changed
and I want to sort the data in column A, workbook1 without having to click
sort.
Thank you in anticipation.