PDA

View Full Version : Sorting Multiple columns programmatically



kiekar
02-27-2007, 03:04 PM
Hello,

Is it possible to sort two columns programmatically using vba in an excel file. I haven't had much luck finding any good tutorials.

Presently I have an excel file which has 3 sheets. I wrote a funtion using the vb editor and added a module. This function extracts certain data from several columns from sheet one which has 21 columns. In order for the function to extract proper data, I need to sort two columns in ascending order.

How would I go about doing this? any help would be much appreciated.

Karl

Simon Lloyd
02-27-2007, 03:09 PM
Welcome to VBAX, not wishing to sound unhelpful but if you have gone as far as writing some code to manipulate data you should be able to record the macro and in corporate it in your code or even just Call the new macro.

Regards,
Simon

kiekar
02-27-2007, 03:24 PM
Simon,

Thanks for the reply. I've never used the recorder before but if it's the simplest way to do this, I'll have to do some homework. Me personally I would prefer to write some vb code to accomplish the task.

Thanks

Karl

Simon Lloyd
02-27-2007, 03:32 PM
The Macro recorder is under tools just turn it on do the tasks you intend stop recording then look at the VB editor, its a great way to start to understand code, granted it does have loads of code that you dont need when its recorded but still a good starting point...if you have trouble post back!

Regards
Simon

mdmackillop
02-27-2007, 04:14 PM
Hi Karl,
Welcome to VBAX
If you're struggling, can you post your workbook with your code and note on just what you're sorting. You can attach a workbook using Manage Attachments in the Go Advanced section

kiekar
02-27-2007, 05:02 PM
Hi,

Thanks all for your help. I did exactly what Simon Suggested. It worked great. I didn't relize when using the recorder the code was viewable.

Regards

Karl