+ Reply to Thread
Results 1 to 17 of 17

Amending macro code - Deleting and moving columns

  1. #1
    Forum Contributor
    Join Date
    03-05-2015
    Location
    Playa Del Carmen, Mexico
    MS-Off Ver
    2016
    Posts
    111

    Amending macro code - Deleting and moving columns

    I have the following code that deletes a lot of columns, copy and pastes one into column B and then sorts by column B.

    Please Login or Register  to view this content.

    I now need to include the previously deleted columns M & O and changed the code to show this....
    Please Login or Register  to view this content.
    .... and this also changed the column I needed to cut and paste to K....

    Please Login or Register  to view this content.
    ... but it isn't working. I do not understand the rest of the code as I didn't create it. The macro simply deletes all records !

    Can anyone please help ?
    Attached Files Attached Files
    Last edited by M12NIX; 12-08-2015 at 11:09 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: Amending macro code - Deleting and moving columns

    The last bit of code looks at column B and if the first two characters in column B do not equal 29 then the entire row is deleted.

    The code looks ok. It would probably be better if you explained in simple English what you are attempting to do and then let us analyze the code to see if it is in fact doing what you want. As it stands it appears to not have any errors.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    03-05-2015
    Location
    Playa Del Carmen, Mexico
    MS-Off Ver
    2016
    Posts
    111

    Re: Amending macro code - Deleting and moving columns

    I work at a hotel and I have a report that has data in columns from A through AO. I want to delete everything except A,B,E,F,G,H,I,J,M,O,P,Q & AL. Then I wish to move the room number column, which after the delete is in Column K, to Column B. Then I wish to sort the records by the room number in column B starting with, in the case of the code above everything starting with 29.

    This code works perfectly. But now I have been asked to keep columns M & O which the original code deleted and I cannot work out why it isn't working with the changes I've made.


    The next step, which I was going to look at later is as follows......

    Once I sort out the issue above is the create a macro (15 in total) for each section of the hotel. We have 3 & 4 digit room numbers and a different person is responsible for different sections and as such requires a different version of this report. This code runs for the 2900 section. I will also need to code for each of the following....

    3 digit room numbers starting with

    {1 & 2},{3,4 & 5},{6 & 7},{8,9,10 & 11},{12,14 & 15},{16 & 17}

    4 digit room numbers starting with

    {25 & 26},{27 & 28},{29},{30},{31},{32},{40,41,42,43 & 44},{51 & 52},{53,54 & 55}

    Hope that makes sense.

    Attached is a before and after. (Before the following code has been completed)

    Please Login or Register  to view this content.
    Last edited by M12NIX; 12-08-2015 at 11:17 AM.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: Amending macro code - Deleting and moving columns

    Will look at later today when I have time available if no one has already supplied a solution.

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Amending macro code - Deleting and moving columns

    Hi M12NIX

    What do these 3 Digit Room Numbers look like...or are they actually 4 Digits?

    10 & 11},{12,14 & 15},{16 & 17}
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Forum Contributor
    Join Date
    03-05-2015
    Location
    Playa Del Carmen, Mexico
    MS-Off Ver
    2016
    Posts
    111

    Re: Amending macro code - Deleting and moving columns

    Hi John, The report shows the rooms in three and four digit formats from 101 - 5528. Each person is responsible for a section. The first is responsible for blocks 1 & 2, the 2nd for 3,4 & 5. Each set of numbers in my comment above is a section that I will need code for. I was thinking of having a blank sheet with 15 macros in for each member of staff to copy and paste the exported report and then simply run their designated macro. Do you think this is the best idea ?

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Amending macro code - Deleting and moving columns

    Hi M12NIX

    I understand this...what I don't understand is what do these 3 Digit Room Numbers look like...
    {1 & 2}...to me this says from 100 to 299


    Versus these 3 Digit Room Numbers...
    {12,14 & 15}...I don't know what this says to me...120 to 129??? 140 to 159??? These overlap with the above.

    Show me what the Room Numbers look like in your grouping.

  8. #8
    Forum Contributor
    Join Date
    03-05-2015
    Location
    Playa Del Carmen, Mexico
    MS-Off Ver
    2016
    Posts
    111

    Re: Amending macro code - Deleting and moving columns

    Many of the buildings have different numbers of rooms. If it is a three digit number the building is known as a single digit, hence the first macro I require is for buildings 1 & 2. The rooms with four digits are known by a double digit (25,26 etc). Here is a full list of all of the rooms.

    101-119,201-219,301-319,401-419,501-519,601-619,701-719,801-819,901-919,1001-1019,1101-1119,1201-1219,1401-1419,1501-1519,1601-1619,1701-1719,2501-19,2601-2619,2701-2719,2801-2824,2901-2934,3001-3038,3101-3138,4001-4024,4101-4124,4201-4224,4301-4324,4401-4424,5101-5124,5201-5224,5301-5324,5401-5424,5501-5524.

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Amending macro code - Deleting and moving columns

    So, these are 4 Digit Numbers...
    1001-1019,1101-1119,1201-1219,1401-1419,1501-1519,1601-1619,1701-1719

  10. #10
    Forum Contributor
    Join Date
    03-05-2015
    Location
    Playa Del Carmen, Mexico
    MS-Off Ver
    2016
    Posts
    111

    Re: Amending macro code - Deleting and moving columns

    yes all numbers i've included have 2 digits afterwards

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Amending macro code - Deleting and moving columns

    Hi M12NIX

    Try this Code on your Raw Data...I've manufactured a Raw Data sheet (Before) and it appears to work for me.

    The Code creates a separate Worksheet for each Grouping. CTRL + x will fire the Code.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    03-05-2015
    Location
    Playa Del Carmen, Mexico
    MS-Off Ver
    2016
    Posts
    111

    Re: Amending macro code - Deleting and moving columns

    Amazing. Thank you so very much. How on earth.....?

    How do I rename the sheets? I thought the following would work but it didn't.
    Please Login or Register  to view this content.
    (These names are in the order that your code shows)

  13. #13
    Forum Contributor
    Join Date
    03-05-2015
    Location
    Playa Del Carmen, Mexico
    MS-Off Ver
    2016
    Posts
    111

    Re: Amending macro code - Deleting and moving columns

    Oh and is there a way to put the new sheets in order starting with 101-299, ending with 5300-5599 ? Sorry to be a pain.

  14. #14
    Forum Contributor
    Join Date
    03-05-2015
    Location
    Playa Del Carmen, Mexico
    MS-Off Ver
    2016
    Posts
    111

    Re: Amending macro code - Deleting and moving columns

    So sorry, the new names are in the order that I'm asking for in my comment at 4:37

  15. #15
    Forum Contributor
    Join Date
    03-05-2015
    Location
    Playa Del Carmen, Mexico
    MS-Off Ver
    2016
    Posts
    111

    Re: Amending macro code - Deleting and moving columns

    Blonde moment.... the new names are in fact in the order of the array in your code.

  16. #16
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Amending macro code - Deleting and moving columns

    Hi M12NIX


    It'll take a bit...perhaps not tonight.

  17. #17
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Amending macro code - Deleting and moving columns

    Hi M12NIX

    You'll need to play with this...been tested but not thoroughly.

    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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. [SOLVED] Amending Macro Code - Deleting & Moving Columns
    By M12NIX in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2015, 03:03 AM
  2. Create VBS code for deleting (moving) row content to new table in separte sheet
    By saslotteroy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2015, 04:31 AM
  3. Code/Macro for deleting empty columns and rows.
    By gautamacharya in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-09-2014, 01:49 PM
  4. Replies: 3
    Last Post: 09-14-2013, 02:22 AM
  5. [SOLVED] auto Deleting contents of certain columns when moving rows between sheets with one click
    By R.Sloan in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 04-18-2013, 04:57 AM
  6. Deleting and moving certain columns of cells from one sheet to another.
    By m0aje in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2012, 11:52 AM
  7. Deleting contents and moving columns
    By tessda in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 07-07-2009, 05:26 PM

Tags for this Thread

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