+ Reply to Thread
Results 1 to 40 of 40

Sort multiple columns based on column header

  1. #1
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Sort multiple columns based on column header

    Hi All

    I need to format a sheet where the number of columns is not fixed. Sometimes the column name "Charged Date" is found in Column X or sometimes in Column Y etc. Basically I’d like to:
    • Find the column header “Charge Date”
    • Apply Autofilter to all columns
    • Sort from Oldest to Newest (Charge Date)

    I already use an array to id the the column headers and reorder the columns (see below) that I found on the forum.
    Please Login or Register  to view this content.
    There must be a way to use the same array to get the result I’m looking for or maybe there’s a faster way………

    Attached is a sample of the actual sheet.
    Attached Files Attached Files

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Hi Langer,

    I am not able to understand you code or the purpose of the find instruction

    the following code will find the Charge Date column and perform a sort. Hope this helps

    Please Login or Register  to view this content.
    If you like my contribution click the star icon!

  3. #3
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    It's returning the error message even though "Charge Date" is in row 1

  4. #4
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Langer,

    Previous post contained a few typing errors

    Please use code shown below

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    Hi OllieB

    Code runs fine but it doesnt actually sort though (I changed "ChargeDate" to "Charge date")

  6. #6
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Quote Originally Posted by Langer101 View Post
    Hi OllieB

    Code runs fine but it doesnt actually sort though (I changed "ChargeDate" to "Charge date")
    Can you post a copy of your workbook (easier to test)?

  7. #7
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    @Langer101,

    I took a copy of the workbook from your first post, inserted the code from post #4 into a module, changed the "ChargeDate" literal into "Charge Date", ran the macro, and noticed that the data had been sorted perfectly. Have copied the updated workbook below
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    I dont doubt it works, just not in conjunction to the other code I already have I've tried a few variations with no luck. As background, I'd like to use the code in a form driven workbook which I could send you but be warned it's messy and will likely cause heart failure

  9. #9
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Langer101,

    You are welcome to post a copy of your workbook, however the sort code is fairly straightforward and should have no interference from other code. Obvious question: you did check the name of the worksheet to be sorted, right? If needed I will gladly have a look at your workbook

    PS - did you try the workbook I posted in #7? Did that one work?

  10. #10
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    Yes I did try #7 and I know it works, the frustrating part is knowing it works but not getting it to run as part of my existing macro.

    I've attached my form driven workbook along with a zipped .csv attachment. Basically the form is meant to take the .csv file and do all the necessary formatting for the user, the last step before saving the workbook being to sort by Charge Date. As I said, it's not the prettiest but for a noob like me it's as good as it gets.
    Attached Files Attached Files

  11. #11
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    I started re-writing the VBA code for the third button, but that is quite an undertaking without the specifications/requirements. That is unfortunately going to cost me too much time. If you take the code I posted at #4 and add it to the CommandButton3 routine just before the ActiveWorkbook.Save instruction it should just work fine.

  12. #12
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    Hi OllieB

    Finally got it to work!!!

    Replaced
    -->With ThisWorkbook.Worksheets("Sheet1").Sort

    with.....
    -->With Sheets("Sheet1").Sort

    Which it what I think you asked me to do in #9. My bad!

    Thanks for the assist, MUCH appreciated!

  13. #13
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Great. I am still itching to re-write your solution. When I have time I will give it a go. If only for the fun of it.

  14. #14
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    That'd be cool. As it is, it's ok for small files but for larger ones it just sucks

  15. #15
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Question:

    in your code you duplicate column Title to Author, and at some point you compare the values in the two columns and clear the author cell if it is the same as the title cell. As the author column is a copy of the title column, would this not always be true, and would the author column thus not always end up being blank? In other words: am I seeing this correctly?

  16. #16
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Question:

    Before the find & replace action on the Publisher column it for example holds a value

    ' Moore, Reavis $ Santa Fe, N.M., 1993 - [1995] $ '

    if I interpret the code correctly you are only interested in the second part and the result should become

    'Santa Fe, N.M., 1993 - [1995]'

    correct?

  17. #17
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    All this stems from the zipped .csv file which is basically the source file that needs to be cleaned up. In it you'll note that one column "S_Title" contains the Title, sometimes an Author (separated by a "/") and Publisher (separated by a "**"). So the idea is to split Title, Author and Publshier into three distinct columns and not to repeat the Title in the Author column if there's no "/" Whatever follows is deleted. ...Hope that makes sense

  18. #18
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Ok. Not really but I am making some good progress in writing a generic solution. Basically the code will be completely generic and will act upon instructions in several worksheets. For example

    Worksheet 1_IMPORT_ACTIONS
    on this worksheet you define which columns of the source data you want to keep or delete, and what the title name and cell format should be if you want to keep the column

    Worksheet 2_DUPLICATE_COLUMNS
    On this worksheet you specify which columns you want to copy &paste (i.e. duplicate) and what name should be assigned to them

    Worksheet 3_FIND_REPLACE
    On this worksheet you specify per column per action, what to search and what the replacement value should be. Obviously you can specify multiple find & replace actions for the same column

    Worksheet 4_SPLIT_ELEMENTS
    Here you can specify which subset you want for a cell value. For example the Charge Date column contains 'DD/MM/YYYY HH:MM:SS' and you are only interested in the date part. On this worksheet you then specify Charge Date as the column, a " " as a separator and 1 as the element to use.


    The idea/concept is that you would not have to write/change any code but can customise everything via the worksheets. Like I said work in progress, but getting there.

  19. #19
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    Re: #16. That's about right

    Just to give you some background:
    I have a group of users with limited excel knowledge that need to take a .csv file and format it extensively. Needless to say I spend a lot of time doing training when they don’t know how to the basics. I figured that by using a form driven macro I could save them and myself a lot of “unproductive” hours.

    Part of the problem is that the .csv file is not as uniform as I’d like, it’s an extract of data from our library management system that ALREADY contains inconsistencies.

    I’ve had help from some of the other forum members but I either couldn’t understand the code (I’m a noob after all) or couldn’t get it to run successfully. It’s frustration seeing code that works but not understanding it or not being able to relate to it.
    http://www.excelforum.com/excel-prog...html?p=3066153
    http://www.excelforum.com/excel-prog...html?p=3052710

    Besides Title I also have a problem with Barcode column particularly if there is a “,” in the relevant column- it indicates two barcodes instead of one. To identify and then to split them hasn’t been easy so I have a big workaround for it that’s far from elegant.
    I’ve also attached the end result excel file so you can what I'm working towards. Note the Barcode 2 and Annotation columns are not present as those columns don’t have any info other than column header
    I only use the columns with the specified column headers but depending on who’s generating the .csv you might end up with more columns

  20. #20
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Ok. Not really but I am making some good progress in writing a generic solution. Basically the code will be completely generic and will act upon instructions in several worksheets. For example

    Worksheet 1_IMPORT_ACTIONS
    on this worksheet you define which columns of the source data you want to keep or delete, and what the title name and cell format should be if you want to keep the column

    Worksheet 2_DUPLICATE_COLUMNS
    On this worksheet you specify which columns you want to copy &paste (i.e. duplicate) and what name should be assigned to them

    Worksheet 3_FIND_REPLACE
    On this worksheet you specify per column per action, what to search and what the replacement value should be. Obviously you can specify multiple find & replace actions for the same column

    Worksheet 4_SPLIT_ELEMENTS
    Here you can specify which subset you want for a cell value. For example the Charge Date column contains 'DD/MM/YYYY HH:MM:SS' and you are only interested in the date part. On this worksheet you then specify Charge Date as the column, a " " as a separator and 1 as the element to use.


    The idea/concept is that you would not have to write/change any code but can customise everything via the worksheets. Like I said work in progress, but getting there.

  21. #21
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    @Langer101,

    Don't worry about the fact that the input is not always consistent or the same. I am trying to make it as flexible and robust as possible. Really making a lot of progress

  22. #22
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    @Langer101,

    Don't worry about the fact that the input is not always consistent or the same. I am trying to make it as flexible and robust as possible. Really making a lot of progress. Almost done

  23. #23
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    @Langer,
    I have built a generic solution. Please check the attached workbook, play with it and give me your feedback.
    Attached Files Attached Files

  24. #24
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    If you have specific questions on how to solve a requirement using the generic solution, let me know!

  25. #25
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    Hi OllieB

    I’ve given it a go and it looks and works great! Best of all I can READ WITH UNDERSTANDING

    I made some minor adjustments along the way

    Removed:
    • pvt_wbk_Target.Worksheets("Sheet2").Delete
    • pvt_wbk_Target.Worksheets("Sheet3").Delete
    The target worksheet will always only have 1 sheet


    Added to Find Replace
    • Publisher CTL*

    Added to Import Actions
    • Column names that needed to be removed to
    o As there may be additional columns that I’m not aware of is it possible to write it the other way around i.e. instead of saying delete the following, say instead delete ALL except for…..
    • YYYY/MM/DD as output format for Charge date

    Added to Column Order
    • Annotation and Volume
    • Added to Column order


    I’ve tried the macro with some of the other lists available. I’ve attached a sample with the following results:

    Barcode1 and 2
    The idea is not to the same barcode twice.
    Ideally Barcode 1 should contain any barcode other than those that start with ‘36180’. These should appear in the Barcode2 column
    If the column only contains 36180 barcodes then we simply call the column Barcode1
    • We have different barcode standards as legacy from two different library management systems hence some barcode start with “OCT*”, C*, 36*etc.

    Charge Date
    I’m not sure why this happens but some dates are in DD/MM/YYYY format it possible to standardise on YYYY/MM/DD instead or is it my settings?

    Price
    Not all the Prices converted into currency

    Finally
    Just thinking about the users that will be using this would it not be best to maybe add this to the ribbon or something? The less they see the better for everyone
    Attached Files Attached Files

  26. #26
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Quote Originally Posted by Langer101 View Post
    Removed:
    • pvt_wbk_Target.Worksheets("Sheet2").Delete
    • pvt_wbk_Target.Worksheets("Sheet3").Delete
    The target worksheet will always only have 1 sheet
    Ok

    Quote Originally Posted by Langer101 View Post
    Added to Find Replace
    • Publisher CTL*
    In my tests I did not need this action as the column split only returned the publisher information

    Quote Originally Posted by Langer101 View Post
    Added to Import Actions
    • Column names that needed to be removed to
    o As there may be additional columns that I’m not aware of is it possible to write it the other way around i.e. instead of saying delete the following, say instead delete ALL except for…..
    • YYYY/MM/DD as output format for Charge date
    Charge Date
    I’m not sure why this happens but some dates are in DD/MM/YYYY format it possible to standardise on YYYY/MM/DD instead or is it my settings?
    Any new columns would remain in the output and thus would serve as a trigger, because the header name would be "strange". If we reverse the logic you would never know that the column was missed. However this would be your choice, I would be happy to change the code.

    Date formatting is a "pain in the butt" as Excel determines AUTOMATICALLY during the import based on the first couple of rows read what the format of the date should be (and yes the regional settings of the workstation do play a role). We can force the format of the column to TEXT but because your input file changes we do not know which column we should take. If the sample output you provided is what has been produced the the only solution I can see is to write a specific routine for transforming dates. Can be done!

    Quote Originally Posted by Langer101 View Post
    Added to Column Order
    • Annotation and Volume
    • Added to Column order
    No problem

    Quote Originally Posted by Langer101 View Post
    I’ve tried the macro with some of the other lists available. I’ve attached a sample with the following results:
    Barcode1 and 2
    The idea is not to the same barcode twice.
    Ideally Barcode 1 should contain any barcode other than those that start with ‘36180’. These should appear in the Barcode2 column
    If the column only contains 36180 barcodes then we simply call the column Barcode1
    • We have different barcode standards as legacy from two different library management systems hence some barcode start with “OCT*”, C*, 36*etc.
    The best solution would be to send me a copy of the "generator" workbook with the most recent changes made by you, and a copy of the input and output. If you can describe your requirements I can build something

    Quote Originally Posted by Langer101 View Post
    Price
    Not all the Prices converted into currency
    Needs a custom solution. I did not face that problem in my testing, but I guess we need to build something for this

    Quote Originally Posted by Langer101 View Post
    Finally
    Just thinking about the users that will be using this would it not be best to maybe add this to the ribbon or something? The less they see the better for everyone
    [/QUOTE]

    Manipulating the ribbon is not something I am very good at. Can we not alternatively create a console worksheet and hide the parameter worksheets (invisible) with VBA project protection so only you can change them?

  27. #27
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    I have just run a test on the version I have and all cells in the Charge Date column have a "general format" as opposed to the date format in your example. have you by any change tried to change the cell format and did that action result in some of the dates being misinterpreted?

  28. #28
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    Hi OllieB

    In response to your queries...

    Date formatting
    My approach has been to strip the time component from the cell value then finished it off by using a recorded macro where I used Text to Columns to change the format.

    Please Login or Register  to view this content.
    Price formatting
    Part of the problem is the lack of standard when the price info was originally captured on our library management system. I’ve noticed that some users used a “.” instead of “,” which was the standard we set for them (you replaced “,” with “.”).
    So in the same column you could have the following:
    39.99.
    39.99
    39,99
    39

    Which should be….
    39.99. -->R39,99
    39.99 -->R39,99
    39,99 -->R39,99
    39 -->R39,00

    Please Login or Register  to view this content.
    I thought of removing all “,” and “." But the individual user settings are still throwing me a curveball. I had a user try my List Generator on her machine and her Price field showed 00030,00 instead of R30,00. I’d like to either enforce different system settings for the duration of the macro (if that’s possible) simply because I suspect that they will be different depending on the user or at the very least fix the type of errors show above

    The barcode formatting is trickier than it should be simply because the logic is a bit convoluted. I'll post more on that in a bit.
    Attached Files Attached Files

  29. #29
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Hi Langer101,

    - processing the CSV file you have provided the date part was isolated fine using my solution, and it remains in the same format as delivered in the CSV. I am not sure what the TextToColumns adds in your solution. If we do not know the source format of the date, or if the format is not consistent in the CSV it would be almost impossible to re-format them into something consistent;

    - replacing a "," with a ".", works in case of US/UK settings as the "." is the decimal notation. On a PC with for example a Dutch regional setting this is not going to work. What I can do is ensure the price is shown correctly for the PC the Excel file is opened on (so somebody with a UK setting would see a "." and somebody with an NL setting would see ","). This would require some additional coding;

    - for barcode processing we could introduce a step that would clear a certain cell for a given condition. That would allow you to clear barcodes starting with CL in column 1 and retain them in column 2, while you could for example clear 381* in column2 while retaining them in column 1

    The file you attached is the old version, so I am not sure why you included it. Do you want to keep using the old version and use the new version I provided to you purely as an example of some code, or do you want to enhance the new version to meet your needs?

    If you want to enhance the new version, please post the last version (and also a CSV file that is causing problems) so no changes that you have made will be lost.

  30. #30
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Langer101, I have read up on the TextToColumn function and see a usage for date and price conversions. Can you please post the most recent version of the workbook, or shall I use the version that I already have?

  31. #31
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Langer101, made the necessary changes to the workbook (master) copy that I have. Noticed the following situation for date conversion

    input:
    15/10/2012
    12/25/2012

    after TextToColumn specifying dd/mm/yyyy

    15/10/2012
    12/25/2012

    notice that the 2nd date has not been changed. The funny thing is that the format of the first date has changed to date, whereas the format of the second date has remained of type general. Using this trick we would know which date was invalid, and can then force the date to dd/mm/yyyy format using code. Your thoughts?

  32. #32
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Hi Langer101,

    Can you please answer the following questions:

    a. what is the date format delivered in the CSV mm/dd/yyyy, dd/mm/yyyy or yyyy/mm/dd?
    b. is this always the same or can it differ per CSV file (in other words dd/mm/yyyy for CSV1 and mm/dd/yyyy fo CSV2)?
    c. if it can be different per CSV, will it at least be consistent within the CSV?
    d. what is the format you would like to have in the output workbook?

  33. #33
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    OllieB, I hope I covered all your questions. Thanks for sticking with it!

    Re:#30 List Generator Ver2 that I sent this morning is the most recent one. I combined the need to rename and format in one command button and added your code to sort by header.

    Re:#29 The users I'm dealing with are not that intuitive hence the form with its step by step approach. Personally I’d prefer your version but it might be best to stick to the form for their sake. I can always run both versions by a sample group to get their opinions.


    Re:Barcode formatting
    We have stock from an external funding source which, in some cases, means that the object has two barcodes: our own and the funding sources. We know the stock with a prefix of 36180 belongs to the external source. To compound matters we’ve changed barcode types hence you have prefixes “360”, “ C” and “OCT” as I mentioned. If there are multiple barcodes and the barcode prefix is 36180 then display that barcode in column Barcode1. All other barcodes would then need to be displayed in Barcode2. I've attached a spreadsheet that, I hope , will go a long to explaining what I mean.

    Re:Dates
    At this point I'll settle for either YYYY/MM/DD or DD/MM/YYYY, as long as its consistant

    Re: the .CSV file
    a. Not sure what you mean but it's shown as 25.08.2011 10:20:59 for example with General as format
    b. As far as I know it should always be the same.
    c. Yes, though I suppose a users settings might result in differences
    d. As an .xlsx file

    ......Never realised excel VBA was so robust, not easy to code but I'm learning
    Attached Files Attached Files

  34. #34
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Langer101,

    Herewith a new version.

    1. Forced date conversion has now been built in. The assumption is that the data format in the CSV file is day/month/year. The user can specify the desired output format on tab 5_FORCE_FORMAT

    2. Forced numeric conversion has now been built in. See tab 5_FORCE_FORMAT - if NUMERIC is specified it uses TextToColumn (always) accepting the "."as a decimal separator which is forced by the find&replace ","by "."in the preceding step, so this should always work

    3. For barcodes I only added for find & replace rules as the generic capabilities appeared sufficient. The only thing I was not able to solve is that if the barcode1 column is empty (and thus removed) that the caption of barcode2 changes back to barcode1. Sorry.

    Let me know your thoughts. IF you encounter problems then please also submit the CSV file that is causing the problem, otherwise it is difficult to test for me.
    Attached Files Attached Files

  35. #35
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    OllieB,

    Strangely enough my first obstacle is a run time error 1004 “Activate method of Worksheet class failed” when I try to run the enable the sheet. Dont know what that's about.

    In the "routine to enforce the format" I run into a "Type mismatch" error message at this point.
    pvt_xls_Cell.Value = Format$(DateSerial(Mid$(pvt_xls_Cell.Value, 7, 4), Mid$(pvt_xls_Cell.Value, 4, 2), Left$(pvt_xls_Cell.Value, 2)), .Cells(pvt_lng_RowNumber, "C").Value)

  36. #36
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Langer,

    I opened the same version and have neither the 1004 error nor the type mismatch.
    - What do you mean by 'enable the sheet'?
    - If you get a type mismatch on that statement then the CSV file contains a date in a different format then specified by you.

    Can you please post the CSV file

  37. #37
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    Sorry, clicked on Open instead of saving it to my machine so ignore the first issue.
    As for type mismatch, i've attached the .CSV file as requested.
    Attached Files Attached Files

  38. #38
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Hi Langer,

    The strange thing is that processing the same CSV I do not receive any errors??

    Dates & prices are all looking fine

    So what I did is I added a check to the software to see if the resulting date is a valid date, if so it stores it else it will show you a message with eh value and the row number where it encountered the problem.

    Revised version enclosed
    Attached Files Attached Files

  39. #39
    Registered User
    Join Date
    12-04-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Sort multiple columns based on column header

    It ran without error (other than trying to delete the sheets that arent there). The date format as I understand it is Custom date. This is a bit of a problem when we want user users to sort from Newest to Oldest and not A to Z.

    I suspect our different settings has an impact on how it treats the values. I'm going to get the same test user as earlier to test your version. I'm curious to see what the end result will look like.

  40. #40
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Sort multiple columns based on column header

    Langer,

    All dates are now converted into proper date serials using the following approach:

    Please Login or Register  to view this content.
    Because the date (internally) is a proper date serial value, sorting is not a problem, regardless of the displayed format.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1