Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

The code that populates the ticket information into the next available row is
Private Sub CommandButton1_Click()
ActiveWorkbook.Sheets("Sheet1").ActivateRange("A2").Select
DoIf IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Value = TextBox1.ValueActiveCell.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

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 SubEDIT: Oh, remember to replace "Sheet1" with whatever the name of your sheet actually is.

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.

![]() |
![]() |
![]() |

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