Automatically Sort Excel Worksheet

Intel / D945gtp
March 24, 2009 at 08:33:07
Specs: Microsoft Windows XP Professional, 2.666 GHz / 1013 MB
Hello Everyone,

I am new to this forum, so thank you for all of your assistance. Here is what I am tring to do.

I have created a worksheet in excel '03 for ticket logging. The worksheet consists of a header row and ten columns with the ticket number being the first column. I created a userform in VB that automatically opens when the file is opened and once the information is entered and the command button clicked it populates the information in to the next empty row. What I have been trying to do is have the worksheet automatically sort by ticket number either when it is first opened or when you exit out of the user form. Any help would be greatly appreciated I am totally blocked on this.

Thank you.

See More: Automatically Sort Excel Worksheet

Report •

March 24, 2009 at 09:26:49
What's your code to add the ticket?

Report •

March 24, 2009 at 11:38:22
The code that populates the ticket information into the next available row is

Private Sub CommandButton1_Click()



If IsEmpty(ActiveCell) = False Then

ActiveCell.Offset(1, 0).Select

End If

Loop Until IsEmpty(ActiveCell) = True

ActiveCell.Value = TextBox1.Value

ActiveCell.Offset(0, 1) = TextBox2.Value

ActiveCell.Offset(0, 2) = ComboBox1.Value

ActiveCell.Offset(0, 3) = ComboBox2.Value

ActiveCell.Offset(0, 4) = ComboBox3.Value

ActiveCell.Offset(0, 5) = TextBox3.Value

ActiveCell.Offset(0, 6) = TextBox4.Value

ActiveCell.Offset(0, 7) = TextBox5.Value

ActiveCell.Offset(0, 8) = ComboBox4.Value

ActiveCell.Offset(0, 9) = ComboBox5.Value


MsgBox "One record written to Sheet1"

response = MsgBox("Do you want to enter another record?", _

If response = vbYes Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
ComboBox1.Value = ""
ComboBox2.Value = ""
ComboBox3.Value = ""
ComboBox4.Value = ""
ComboBox5.Value = ""


Unload Me
End If

End Sub

Report •

March 24, 2009 at 13:05:46
Put this in the ThisWorkbook section:
Private Sub Workbook_Open()
  Dim c As Range
  Set c = Worksheets("Sheet1").Cells
  c.Sort Key1:=c.Range("B1"), Header:=xlYes
End Sub
EDIT: Oh, remember to replace "Sheet1" with whatever the name of your sheet actually is.

Report •

Related Solutions

March 25, 2009 at 05:33:26

Thanks for the help. I pasted the code in the end and also the beginning of the code but it didn't not sort at all. I am a novice at Visual Basic Editor and this is the first macro I ever wrote. You said to put the code in the ThisWorkbook section, but I do not see a section by that title. Do you need to see the entire code? Or can you tell me what I'm doing wrong.
Thank you.

Report •

March 25, 2009 at 06:50:13
Razor Thanks so much but I figure it out.

Report •

Ask Question