+ Reply to Thread
Results 1 to 14 of 14

Code to delete selected columns and rearrange columns in order

  1. #1
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,175

    Code to delete selected columns and rearrange columns in order

    Hello experts
    With the help of a code, I am trying to delete unwanted columns and re arrange the sheet in a required order. I have recorded a macro to do the above. I need your expertise to help me with a shorter correct code to do the above. Please note that I want to delete and arrange the columns in the same sheet.
    Thank you in advance.
    fyi, This post was unsolved in a forum where I haven't received any response.
    https://www.msofficeforums.com/excel...e-columns.html
    Last edited by RAJESH SHAH; 04-13-2023 at 03:33 PM. Reason: #Solved by beyond excel

  2. #2
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Code to delete selected columns and rearrange columns in order

    Hi. Try with:

    PHP Code: 
    Columns("X:Y").Cut
    Columns
    ("D:E").Insert Shift:=xlToRight
    Range
    ("N:N,P:Z").Delete Shift:=xlToLeft 
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Post Re: Code to delete selected columns and rearrange columns in order


    ( removed too late )

  4. #4
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,175

    Re: Code to delete selected columns and rearrange columns in order

    Hello beyond excel. The code is not running when I assign it to a button. It works with only the sheet which is open. I even tried editing it but it is not working on the B2B sheet unless it is open and I run by using F8.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,175

    Re: Code to delete selected columns and rearrange columns in order

    Marc. Which part did you not understand. Please tell me so that I can explain. I have also inserted an expected result sheet.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Code to delete selected columns and rearrange columns in order


    I cleared my post 'cause I could not see you already get some help …

    If you did not receive an answer whatever the forum so that means your initial post is under the level expected
    as the initial post must contain a crystal clear complete technical elaboration of the need with nothing to guess
    as guessing can't be coding or may just be a waste of time …

    So the answers are at the level of the initial post, if you did not make any effort in your initial post so very do not be surprised …

  7. #7
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,175

    Re: Code to delete selected columns and rearrange columns in order

    Got it right now. Now it is working with the button. Thanks beyond excel
    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Code to delete selected columns and rearrange columns in order

    RAJESH SHAH:

    Honestly, I thought you already knew.
    But it doesn't matter because now I explain it to you:

    a) Start by comparing your code from post #4 with what I'll show you below:
    Please Login or Register  to view this content.
    b) The difference is those 3 dots that we see before the two Columns and Range.

    c) What do those "dots" mean?...

    d) Simply that both the 'Columns' and the 'Range' refer to the "B2B" sheet that you initially put when writing: With Sheets("B2B").

    Understood?

    e) And doing that you don't need to select the B2B sheet and you can be with any other sheet activated.

    f) By the way: by not putting those points in your post #4, the two 'Columns' and the 'Range' referred to the active sheet and that's the big difference.
    Last edited by beyond Excel; 04-13-2023 at 04:24 PM.

  9. #9
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,175

    Re: Code to delete selected columns and rearrange columns in order

    Clearly understood now. Thanks once again beyond excel.

  10. #10
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Code to delete selected columns and rearrange columns in order

    Until next time.

  11. #11
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,175

    Re: Code to delete selected columns and rearrange columns in order

    The next time is near by. Preparing the sample file to post the next query in a new thread. 😜

  12. #12
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Code to delete selected columns and rearrange columns in order

    .
    Ja ja ja

  13. #13
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,175

    Re: Code to delete selected columns and rearrange columns in order

    Posted "code to replace unapproved names using user form". It will not be too complicated for you to find a solution, I am very sure.

  14. #14
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Code to delete selected columns and rearrange columns in order

    I'll see it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need macro code to rearrange columns and to delete unwanted columns
    By Giri.hb in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 08-16-2019, 03:00 AM
  2. [SOLVED] Delete all columns besides the two selected
    By shane01101 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-12-2014, 06:32 PM
  3. [SOLVED] VBA code to rearrange data into multiple columns
    By shinobi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2013, 06:33 AM
  4. How can I rearrange columns value in one fixed order?
    By sonupal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2013, 09:24 AM
  5. [SOLVED] Delete the selected columns!
    By devpp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-28-2013, 06:27 AM
  6. Rearrange selected columns automatically
    By sujitnilu in forum Excel General
    Replies: 2
    Last Post: 06-22-2013, 01:38 AM
  7. [SOLVED] Macro to delete columns except selected columns
    By VKR in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-07-2013, 10:01 AM

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