Computing.Net > Forums > Database > Automatically Sort Excel Worksheet

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Automatically Sort Excel Worksheet

Reply to Message Icon

Name: VillageGirl
Date: March 24, 2009 at 08:33:07 Pacific
OS: Microsoft Windows XP Professional
CPU/Ram: 2.666 GHz / 1013 MB
Product: Intel / D945gtp
Subcategory: General
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: March 24, 2009 at 09:26:49 Pacific
Reply:

What's your code to add the ticket?


0

Response Number 2
Name: VillageGirl
Date: March 24, 2009 at 11:38:22 Pacific
Reply:

The code that populates the ticket information into the next available row is

Private Sub CommandButton1_Click()
ActiveWorkbook.Sheets("Sheet1").Activate

Range("A2").Select

Do

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

Range("A2").Select

MsgBox "One record written to Sheet1"

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

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

TextBox1.SetFocus

Else
Unload Me
End If


End Sub


0

Response Number 3
Name: Razor2.3
Date: March 24, 2009 at 13:05:46 Pacific
Reply:

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.

0

Response Number 4
Name: VillageGirl
Date: March 25, 2009 at 05:33:26 Pacific
Reply:

Razor,

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.


0

Response Number 5
Name: VillageGirl
Date: March 25, 2009 at 06:50:13 Pacific
Reply:

Razor Thanks so much but I figure it out.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Database Forum Home


Sponsored links

Ads by Google


Results for: Automatically Sort Excel Worksheet

Automatic Sort sheets in excel 2003 workbook www.computing.net/answers/dbase/automatic-sort-sheets-in-excel-2003-workbook/739.html

Multiple Excel Worksheets to Access www.computing.net/answers/dbase/multiple-excel-worksheets-to-access/115.html

converting excel worksheets to access tables www.computing.net/answers/dbase/converting-excel-worksheets-to-access-tables/651.html