Hi All,
Please I need help with a vba code that will auto sort two columns in my database when entries are made into the database using the inbuilt Excel Userform.
I have a database with names, addresses and other details. The columns are twelve in number currently, but may increase in future. I make entries into the database using the Excel 2007 built-in User Form.
Columns 2 and 4 contain the first names and last names, respectively. And I want the database to be AUTOMATICALLY sorted based on those two columns. Column 4 to be sorted first (i.e. the last name) and column 2 second (i.e. the first name) in case there are people with the same last name. I want this automatic sorting to occur the moment the details appear in the database from the userform.
Going through the forum threads, I came across the following code (see below). Unfortunately the code below works ONLY when the workbook is opened, in addition to other areas of my need that it does not meet.
When I tried the code above, I realised that, although it works, it sorts only ONE column - i.e. column 4. I would need it to sort both columns 4 and 2 - in that order. Secondly, using the code above, the automatic sorting occurs ONLY when the workbook is opened. I require the automatic sorting to occur when the details appear in the database from the userform. That is to say, the moment I finish entering each record in the userform and it is transferred onto the database, the database is automatically sorted in ascending order based on columns 4 and 2, respectively.
Also, I don't know whether it is best to place the vba code in a Module or in the specific sheet where the database is.
I should be very grateful, please, for help with a vba code that meets my needs as explained above.
Thanks in anticipation.
Newqueen
Bookmarks