+ Reply to Thread
Results 1 to 16 of 16

Moving Numbers ONLY

  1. #1
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Moving Numbers ONLY

    Hey Guys,

    Here is a copy of the macro I've been trying to get working, could someone help make it better and fix it for the bug what I've come across

    Basically, I'm trying to move any cell in the ADM:ADV range what has a number in it across to columns at the left (M to V) for example)

    Thanks in advance
    - Hyflex

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,627

    Re: Moving Numbers ONLY

    Will LARGE function help withou need of the loop if your new values can be in descending order? Or SMALL for ascending

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Moving Numbers ONLY

    No wonder why you getting errors!
    I have to admit this is the first time in my life to see Range("ADW19:ADW")
    I have never been to this part of excel. My limit has been two digits range
    The code works, but not if a cell is empty. I kept getting errors until I put some dummy data ine each cell. I think you will have a fun of using this code.
    You could also change the lastrow line in to
    Please Login or Register  to view this content.

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Moving Numbers ONLY

    Hyflex,

    It's difficult to test this without a sample workbook, but here's a revamped version of that code you provided, which should work quicker and be error free:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Moving Numbers ONLY

    Quote Originally Posted by zbor View Post
    Will LARGE function help withou need of the loop if your new values can be in descending order? Or SMALL for ascending
    Hi Zbor,

    I'm slightly confused by what you said :S

    Quote Originally Posted by AB33 View Post
    No wonder why you getting errors!
    I have to admit this is the first time in my life to see Range("ADW19:ADW")
    I have never been to this part of excel. My limit has been two digits range
    The code works, but not if a cell is empty. I kept getting errors until I put some dummy data ine each cell. I think you will have a fun of using this code.
    You could also change the lastrow line in to
    Please Login or Register  to view this content.
    The last row always has to be done by column A because of how my document is designed, I cant get around the issue where if the range is empty it throws up an error.

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,627

    Re: Moving Numbers ONLY

    Well just make loop for i from 1 to COUNT values in A column with application.worksheetfunction.large("A1:A60000", i)

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Moving Numbers ONLY

    John,
    I have put some dummy data in ADM19:ADW19(Was really good fun to go all the way to these columns) and the code works

  8. #8
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Moving Numbers ONLY

    Hey Tigeravatar,

    Thanks for your reply, I'm really confused as to why yours has two ranges in RngCheck

  9. #9
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Moving Numbers ONLY

    Hyflex,

    It is because the code you posted in your original post skips column ADU. So you have AD.. M,N,O,P,Q,R,S,T and then V,W. Between T and V should be U, but your code doesn't have that, so the code I provided mirrors that, hence the two ranges "ADM:ADT,ADV:ADW"

  10. #10
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Moving Numbers ONLY

    Hey tigeravatar,

    Ahh my bad, I clearly don't know my alphabet. It was 10 columns from ADM, so AD.. M, N, O, P, Q, R, S, T, U, V

    I just tried to modify your macro but I can't get it to work now.

  11. #11
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Moving Numbers ONLY

    Because it is now a continuous block of cells, the macro can be somewhat simplified:
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Moving Numbers ONLY

    Amazing, you never fail to make perfect macros.

    One last change is I need to make all of the numbers turned into 0 decimal places. I tried the following:
    Please Login or Register  to view this content.
    but anything what isn't a number is removed for some reason
    Last edited by Hyflex; 11-05-2012 at 12:25 PM.

  13. #13
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Moving Numbers ONLY

    Still been unable to fix this last small bug, anyone have any ideas?

  14. #14
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Moving Numbers ONLY

    Try:
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Moving Numbers ONLY

    Thanks tigeravatar, it seems like the issue is in the first part of the macro.

    If over at: ADM19:ADV & LR is a number it should move it to the left but if it's blank it shouldn't do anything.

    It wipes cells what have text in over at the left otherwise.

  16. #16
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Moving Numbers ONLY

    So the cells at the left are not already blank, but have existing text in them, and the macro is overriding them to be blank cells when it brings the numbers over from the ADM:ADV range?

    If that is the case, give this version a try:
    Please Login or Register  to view this content.

+ 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