PDA

View Full Version : Solved: sorting



MUSASHI
10-15-2005, 08:02 PM
Hello,

long time no see.

Probably something very simple , I have searched but overlooked or couldnt find exactly what I wanted.

I am using a userform to pass data to a sheet. I have 2 command buttons on the form by the way, enter and cancel.

I use textboxes and a combobox, to fill basically 8 columns of data per row.

Upon an action, not sure whats best or available, preferably when I enter the new row of data, I want to sort by the first 2 columns.

Any ideas...

Thanks
Mus

Bob Phillips
10-16-2005, 04:36 AM
Not sure what the question is. You want to sort by the first two columns when you enter new data, so sort by the first two columns when you enter data. Job done!

MUSASHI
10-16-2005, 06:46 AM
well, I assume you arent punishing me for some unwritten rule, but, I will try again.

looking for some code that will automate the sort....I have a USERFORM. On the USERFORM it has a combination of 8 items that require input...(text, combobox, etc)

The data captured in that USERFORM is placed on a WORKSHEET via a command button, in the next empty row etc etc.

Say for instance something like this

Private Sub cb_enter_click()
Dim LastRow As Long
'make sure manf is entered
Select Case cb_manf.Text
Case Is = "Required!"
MsgBox "Sorry, but you must put in a manufacturer! "
Exit Sub
Case Is = ""
MsgBox "Sorry, but you must put in a manufacturer! "
Exit Sub
Case Else
'do nothing
End Select
Select Case tb_product.Text
Case Is = "Required!"
MsgBox "Sorry, but you must enter a product! "
Exit Sub
Case Is = ""
MsgBox "Sorry, but you must enter a product! "
Exit Sub
Case Else
'do nothing
End Select
Select Case tb_sbv.Text
Case Is = "Required!"
MsgBox "Sorry, but you must enter the Solids by Volume! "
Exit Sub
Case Is = ""
MsgBox "Sorry, but you must enter the Solids by Volume! "
Exit Sub
Case Else
'do nothing
End Select
Select Case tb_price.Text
Case Is = "Required!"
MsgBox "Sorry, but you must enter the Price per Gallon! "
Exit Sub
Case Is = ""
MsgBox "Sorry, but you must enter the Price per Gallon! "
Exit Sub
Case Else
'do nothing
End Select
LastRow = Worksheets("materialmaster").Range("A65536").End(xlUp).Row + 1
Cells(LastRow, 1).Value = cb_manf.Value
Cells(LastRow, 2).Value = tb_product.Value
Cells(LastRow, 3).Value = tb_color.Value
Cells(LastRow, 4).Value = tb_sbv.Value
Cells(LastRow, 5).Value = tb_price.Value
Cells(LastRow, 6).Value = tb_thinner.Value
Cells(LastRow, 7).Value = tb_thindol.Value
Cells(LastRow, 8).Value = tb_comment.Value


Unload Me
End Sub

What I want is to sort all the records by the first 2 columns as keys..on some action, versus a user selecting the sort function. Say for instance, on sheet activate (not really the one I want, because the last record wont be sorted..) or some other action...
Thanks:bow:

geekgirlau
10-17-2005, 02:48 AM
Can't you just add the sort command just before the Unload? Something like


Columns("A:H").Sort _
Key1:=Range("A2"), Order1:=xlAscending, _
Key2:=Range("B2"), Order2:=xlAscending, Header:=xlYes

MUSASHI
10-17-2005, 06:58 PM
yes, not quite it, but got it working.

thanks!