Trim the code

  • Good Day,


    Require assistance in trimming the below code + borders to be included for the range that consist text.


    Please help to trim the code - Anna

  • You can start by removing all the Selects. Your code selects the Input and output sheets several times and it isn't necessary at all.


    Why are you selecting columns separately? It's not necessary to select and they could be copied together.


    Attach an example of your workboo.

  • royUK Thanks for your reply. Because I require column order to be rearranged in specific order.


    Input reports are stored in different formats. Before fetching the output ( Default template) I require the data to get delimit and rearrange the column order and update the output.


    Attaching the test file shortly.

  • Try this.


    If you aren't copying formulas then the code could be made shorter

  • You could actually improve the workbook by formatting the destination sheet's data as a Table. Then you wouldn't need to set the borders up in the code.

  • royUK

    I receive 5-6 columns of data from a client.


    Scenario 1

    column_e, column_b, column_a, column_c,column_d


    <Reordering the columns and delivering the outputs>


    Reqd. Output

    column_a,column_b,column_c,column_d,column_e


    Scenario 2

    column_a, column_c, column_e, column_d,column_b


    Reqd. Output

    column_a,column_b,column_c,column_d,column_e


    Scenario 3

    column_a, column_c, column_e, column_d,column_b,column_f


    Reqd. Output

    column_a,column_b,column_c,column_d,column_e


    As you can see the reqd. output, column order is fixed (column_a,column_b,column_c,column_d,column_e),

    But I get inputs in different column order. I'm looking for a code which can work dynamically. Irrespective of the input, the columns should get rearranged to a,b,c,d,e..




  • You need to get your clients to provide data in an acceptable format.


    If they all use the same headings then you might be able to use AdvancedFilter, but making it dynamic would be complicated.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!