+ Reply to Thread
Results 1 to 9 of 9

If cell equals "CR" then make cell to left negative and delete "CR".......

  1. #1
    Forum Contributor
    Join Date
    09-09-2013
    Location
    California, USA
    MS-Off Ver
    MS 365 Subscription
    Posts
    130

    If cell equals "CR" then make cell to left negative and delete "CR".......

    What I need it to do is look in a large range for and cell that equals "CR", then change the cell to the left of it to a negative and remove the "CR".

    I have a code that I was working for a day. But now when I run the macro, it no longer does anything. Could it be a setting that I am overlooking, or is there a more reliable way to write this code?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: If cell equals "CR" then make cell to left negative and delete "CR".......

    I am sorry my friend but your code is no good.

    1. If you are looking at a large range the last thing you want to do is to use a loop.


    2.
    Please Login or Register  to view this content.
    Will return the last row in column A.
    Please Login or Register  to view this content.
    Will return the last row in column Y.

    What makes you sure that Column Y is your longest column?

    Perhaps you should use
    Please Login or Register  to view this content.
    I will rewrite your code for you.

    This is more complicated than your code but hundreds of times faster.
    Mainly because it uses the find function rather than a loop.

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 01-14-2016 at 01:39 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: If cell equals "CR" then make cell to left negative and delete "CR".......

    You said the cell to the left, but Offset(0,1) is the cell to the right. Offset(0,-1) would be the cell to the left. Not sure which you want, adjust the code below accordingly.

    Please Login or Register  to view this content.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  4. #4
    Forum Contributor
    Join Date
    09-09-2013
    Location
    California, USA
    MS-Off Ver
    MS 365 Subscription
    Posts
    130

    Re: If cell equals "CR" then make cell to left negative and delete "CR".......

    Quote Originally Posted by walruseggman View Post
    You said the cell to the left, but Offset(0,1) is the cell to the right. Offset(0,-1) would be the cell to the left. Not sure which you want, adjust the code below accordingly.

    Please Login or Register  to view this content.
    Thank you very much for helping me!
    I just testing this code and it worked, but it does give me an error on the "Loop..." line once the code is done.
    The error message says "Run-time error '91': Object variable or with Block variable not set."

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: If cell equals "CR" then make cell to left negative and delete "CR".......

    walruseggmans code would work if you inserted the two lines

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    The reason being that you are Deleting CR, eventually there will be no CR to find giving you an error.

    you should also remove all reference to c.address for the same reason.
    Turning off screen updates would make it even faster.

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 01-14-2016 at 01:49 PM.

  6. #6
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: If cell equals "CR" then make cell to left negative and delete "CR".......

    @mehmetcik: Good point, wasn't thinking about that.

    @pas: You'll need to also remove And c.Address <> FirstAdd from mehmetcik's modified code.

  7. #7
    Forum Contributor
    Join Date
    09-09-2013
    Location
    California, USA
    MS-Off Ver
    MS 365 Subscription
    Posts
    130

    Re: If cell equals "CR" then make cell to left negative and delete "CR".......

    Quote Originally Posted by mehmetcik View Post
    walruseggmans code would work if you inserted the two lines

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    The reason being that you are Deleting CR, eventually there will be no CR to find giving you an error.

    you should also remove all reference to c.address for the same reason.
    Turning off screen updates would make it even faster.

    Please Login or Register  to view this content.
    This code worked great!! Thank you guys very much for helping me

  8. #8
    Forum Contributor
    Join Date
    09-09-2013
    Location
    California, USA
    MS-Off Ver
    MS 365 Subscription
    Posts
    130

    Re: If cell equals "CR" then make cell to left negative and delete "CR".......

    I had one more question about this code. I saved this macro in a master file that opens at startup that is hidden so that I can use this macro in all my workbooks.
    When I run the macro in another workbook it work, but it seems to continue to loop. It locks up excel until I hit the ESC key.
    But when I run this code in the workbook that it is saved in, it does not lock up excel and works just fine.

    Do you know why this could be?

    Thank you

  9. #9
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: If cell equals "CR" then make cell to left negative and delete "CR".......

    I cannot see any reason for that.

    I pasted the last code into my Peersonal workbook, also a hidden book and ran the macro with no issues.

+ 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. Replies: 35
    Last Post: 01-13-2016, 02:16 AM
  2. Replies: 1
    Last Post: 11-04-2015, 04:34 AM
  3. "Form and macro" to delete "Active" cell contents.
    By wanty in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2013, 11:33 PM
  4. [SOLVED] Delete row if cell in Column N equal "Different" or Column P equals "Blank"
    By Cyberpawz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2012, 08:25 AM
  5. Replies: 5
    Last Post: 06-26-2006, 09:23 PM
  6. If changed array formula reduce ""\""\""\ - signs to #Missing, will it make ...
    By Maria J-son in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2006, 08:25 AM
  7. Replies: 6
    Last Post: 01-08-2006, 06:20 PM

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