+ Reply to Thread
Results 1 to 19 of 19

Macro to move cells to the right based on criteria

  1. #1
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2010
    Posts
    110

    Macro to move cells to the right based on criteria

    Hi Experts,

    I know this should be easy but I am struggling with this one. I need to look at column A and for those cells that do not have a value between 1 and 9 I need to move those over to the right one column. If they are between 1 and 9 I need them to stay in place. I am working on a PDF to Excel conversion and the data is not coming in cleanly. I will have a lot of clean up to do so I hate to ask for all of the help at once if I am able to do some of it. I am just stuck on this first piece .

    Any help would be greatly appreciated.

    I can attach a spreadsheet if needed but I the rest of the data is all over the place at the moment.

    Thanks,
    theglitch

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Macro to move cells to the right based on criteria

    Hi theglitch,

    Try this while on the sheet with the data in column A:

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Macro to move cells to the right based on criteria

    Thanks Robert.

    Maybe I said it the wrong way but I am guessing it would be a quick fix but I need it to go the other way. Right now it is moving the 1 though 9's over one column but I need the non 1 through 9's to move. Thank you very much for the start though. I can try to mess with it if you do not have time.

    Thanks again
    Last edited by theglitch; 03-30-2020 at 06:42 PM.

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Macro to move cells to the right based on criteria

    Just add in an else clause like so:

    Please Login or Register  to view this content.
    I've also slightly shortened the code.

    Robert
    Last edited by Trebor76; 03-30-2020 at 06:49 PM.

  5. #5
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Macro to move cells to the right based on criteria

    Thank you very much that worked. I really appreciate the help. I will probably be posting another help soon as I have another one I can't figure out. But thank you very much for your help I will mark closed. Thanks again.

  6. #6
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Macro to move cells to the right based on criteria

    Sorry to bother you again. If you want feel free to not answer. But if I have values in Column B that I want to keep or values that go into other columns say to AG is there a way to shift all of the cells to the right and not overwrite the cell in B with the value in A. Thanks again. I am sorry I am not clear or asking everything at once. I am trying to build this on the fly and I am not clear myself.

  7. #7
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Macro to move cells to the right based on criteria

    is there a way to shift all of the cells to the right and not overwrite the cell in B with the value in A
    Try this:

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,519

    Re: Macro to move cells to the right based on criteria

    Try on a copy of your workbook first.
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Macro to move cells to the right based on criteria

    thank you Robert and Jolivanes,

    I went ahead and attached a spreadsheet with a before and after of what I am trying to do along with the PDF of what I am starting with. I have the PDF converted to Excel and copied to the cells on the left side of the yellow line. I do not care if the changes happen in place or off to the right like I have them for demonstration purposes. I will try to lay out what I think needs to happen but please ask questions as I am sure I will am not going to be clear.

    Thank you again for any help you can provide, I am sorry I did not get back to you last night my internet went out.

    In the section to the right of the yellow line. (I do not need the yellow line just there to show the before, on the left and after on the right)

    1. move the data over from AH to AI but NOT for AH if the value is between 1 and 9
    2. move the data over from AJ to AK but NOT for AJ if AJ has some value in it (I am not sure what that column might have in it yet)(I am guessing similar to what you did already Robert but I would change the criteria)
    3. move the data over from AL to AM but NOT for AL if the value is between 1 and 9, in AH
    4. move the data over from AN to AO but NOT for AN if AN has some value in it (I am not sure what that column might have in it yet)
    5. move the data over from AO to AP but NOT for AO if AO has some value in it (I am not sure what that column might have in it yet)

    I think the same process would start over in AP for the second set of data, there are two columns(chunks) of data, see pdf. Please let me know if you need any more data or if I can try to be of any more assistance and thank you both again in advance. I am trying but this is way above my ability.

    Thanks,
    theglitch
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Macro to move cells to the right based on criteria

    Remove (delete the rows) from the "EXPLANATION OF CODES" section, clear the data from the range AH6:AW[last row] and then run the following while on the sheet with the raw data in columns A to P:

    Please Login or Register  to view this content.
    Robert

  11. #11
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Macro to move cells to the right based on criteria

    Thank you very much Robert for the response I will try and let you know. I really do appreciate ALL of the help.

  12. #12
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Macro to move cells to the right based on criteria

    Hi Trebor76,

    I know I am being a pain and I am sorry, but it is working for columns AH to AO but it it not moving columns AP to AT to arrange them like AH to AO. Is there something I need to do to make both sets of columns work in the code above? Like I said the first set is working perfectly, thank you very much.

    Thanks again,
    theglitch

  13. #13
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Macro to move cells to the right based on criteria

    The second part is for when the code identifies the contents of Col. A as being a serial number.

    Trying stepping through the code (by pressing F8) to see why this section isn't working as expected.

  14. #14
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Macro to move cells to the right based on criteria

    Hi Trebor76,

    I can get everything but AP through AW to work, I added a new file Book7revised to show what I mean (how AP to AW should look). the two sections in the pdf and the two sections in the spreadsheet should be formatted the same way. The first section works perfectly AH through AO. I am not sure if I need to copy the whole code and try to change for the second section AP though AW or if there is an easier way. I know you are way better and smarter than I am so I really do appreciate all of your help on this.

    I really can not say how much I appreciate all of your help,
    thglitch
    Attached Files Attached Files

  15. #15
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Macro to move cells to the right based on criteria

    Have a look at Sheet2 on the attached as I've used formulas to extract the data in the required format. You can convert these into a macro if needed.

    Note IsCellDate is a function I wrote as there's no worksheet equivalent for ISDATE that I know of.

    Regards,

    Robert
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Macro to move cells to the right based on criteria

    Hi Robert,

    I converted All to macros and added to the attached file. The only issue I have now is Column AR. It does not remove the data or clear it out based on any criteria. I am not smart enough to figure out what is the best way to approach this based on what you have done so far. Would you be able to let me know how to do this last piece. Once again that you very much for the help. File attached with what I have done so far.

    Thanks,
    theglitch
    Attached Files Attached Files

  17. #17
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Macro to move cells to the right based on criteria

    The only issue I have now is Column AR. It does not remove the data or clear it out based on any criteria.
    That's because Col. AR in your sample in thread 14 had nothing in that column

    Ok - this my last try:

    Please Login or Register  to view this content.
    If any formula columns i.e. AH to AW are not extracting properly, work out what formula will do the job and then add it to the particular line of code above as I have done.

    I hope it all woks out from here.

    Regards,

    Robert

  18. #18
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2010
    Posts
    110

    Re: Macro to move cells to the right based on criteria

    Thank you again for all of your help. I really do appreciate all of your time with this. I think I can take this and make it work. All the best to you.

    Thanks again

  19. #19
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Macro to move cells to the right based on criteria

    Thanks for the feedback and you're welcome

+ 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] Macro to move cells in 2 rows after word criteria to specific cells in other sheet
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-20-2018, 11:41 AM
  2. [SOLVED] Macro to clear cells in range & move up if certain cells meet criteria
    By samder68 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-09-2016, 10:52 PM
  3. [SOLVED] Macro to move data from one worksheet to another based off of criteria;
    By KLiving in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-17-2015, 12:41 PM
  4. [SOLVED] Macro to Move Rows to New Worksheets Based on Criteria & Then HIDE & Move Back
    By abro0821 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-22-2014, 04:00 PM
  5. Macro - Move entire row to other tab based on specific criteria
    By thomasp in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-08-2013, 11:29 AM
  6. Macro to move rows, row by row, based upon specific criteria.
    By luke8182 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-20-2012, 01:05 PM
  7. Macro to move cell down a row based on criteria
    By neilcarden in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-23-2009, 05:20 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