Consulting

Results 1 to 5 of 5

Thread: Solved: sorting

  1. #1
    VBAX Regular MUSASHI's Avatar
    Joined
    Oct 2004
    Location
    Corpus Christi, Texas (Very South)
    Posts
    44

    Solved: sorting

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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!
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular MUSASHI's Avatar
    Joined
    Oct 2004
    Location
    Corpus Christi, Texas (Very South)
    Posts
    44
    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

    [VBA]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 [/VBA]

    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

  4. #4
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Can't you just add the sort command just before the Unload? Something like

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

  5. #5
    VBAX Regular MUSASHI's Avatar
    Joined
    Oct 2004
    Location
    Corpus Christi, Texas (Very South)
    Posts
    44
    yes, not quite it, but got it working.

    thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •