+ Reply to Thread
Results 1 to 27 of 27

VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

  1. #1
    Registered User
    Join Date
    07-06-2015
    Location
    Central, Oregon
    MS-Off Ver
    2013
    Posts
    56

    VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Hi,

    I have a problem with my search blowing up with a server error so while I'd like to benefit from all the other expertise before reinventing the wheel I'm resigned to ask for help. I know there's lots of wonderful help here but I apologize for my search problems in advance. Sorry to vent.

    SO HERE IS WHAT I NEED.
    I need a macro I can run on my active worksheet in cell range N:17 to NN:300 that will search for cells with cell color RGB(0, 255, 0) and insert the value 1 in them so I can make use of my SUMIFS formula outside of this range which looking for certain row conditions and determining totals.


    In back ground; For a previous attempt without programming I tried the fill blank cells in the range it filled all the cells. That was good but when I tried the search and replace and choosing cell format it would not find a value. With out the format it found all the 1s but once I selected format no results regardless of color. I looked all over online and Excel's finicky find is well known in later generations. It seems simple enough but strange response.

    Anyway I'd appreciate it if someone had a simple macro for this.

    Gratitude in advance!!

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    May be as start point
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Registered User
    Join Date
    07-06-2015
    Location
    Central, Oregon
    MS-Off Ver
    2013
    Posts
    56

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    YasserKhalil,

    Thank you for your response. I will try yours now. I had gotten as far as the code below while waiting and it does work part way. Meaning that it hangs up the program to where I can't do anything while it's running and then have to hit Ctrl + Break. In result after the Ctrl + Break it does put 1's in the correct cells half way down and then hangs. Yet all the cell values are empty and the mix of same blue, green, and no fill boxes is all similar. Any thoughts? I will try your but curious why mine does not work.

    Please Login or Register  to view this content.
    Thank you sir.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Maybe:

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Maybe:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Try this version
    Please Login or Register  to view this content.

  7. #7
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Hello KG869,

    Please try the Code below;

    Please Login or Register  to view this content.

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  8. #8
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Hello KG869,

    You will notice that my code uses no loops and is fast.

    You may want to include ScreenUpdating=False and then True at the end, before End Sub.

    Please Login or Register  to view this content.

    Regards.

  9. #9
    Registered User
    Join Date
    07-06-2015
    Location
    Central, Oregon
    MS-Off Ver
    2013
    Posts
    56

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Ok so overwhelming and wonderful responses from all. I have had a chance to try beyond John H. Davis' response. That one does work. It consumes the resources of excel completely like my first one but it does complete and work well. I did go back in and turn screen update off then back on again thinking that might help. So can anyone tell me from all of the responders is the reason excel hangs really because there are so many cells to check a put a value in. Is there more efficiency some other way. Maybe I need to take the time to evaluate the remaining generous responses but I don't want to lose my audience with my blazing speed of initiation here. I'm not real fast but I can lift heavy things. Just kidding. Just older and slower than I used to be. I am not real good at VBA and so reading the additional code taek a while.

    Thanks all, your help is tremendously appreciated!

  10. #10
    Registered User
    Join Date
    07-06-2015
    Location
    Central, Oregon
    MS-Off Ver
    2013
    Posts
    56

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Winon,

    Fast is what I'm looking for. I will try it. The last comment I made was a slow type and so it got inserted after your reply. Thank you all again. You guys are awesome!!

  11. #11
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Hi KG869,

    Maybe yo have a lot of other things happening behind the scenes at the same time?

    So can anyone tell me from all of the responders is the reason excel hangs really because there are so many cells to check a put a value in. Is there more efficiency some other way.
    If that includes my Proposed solution, then please try the Code below;

    Please Login or Register  to view this content.

    Regards.
    Last edited by Winon; 02-08-2017 at 03:31 PM. Reason: Where did my Code tags go?:(

  12. #12
    Registered User
    Join Date
    07-06-2015
    Location
    Central, Oregon
    MS-Off Ver
    2013
    Posts
    56

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Winon,

    Maybe, I do have a knack for breaking computers even with 16GB ram but the processor is i5 and I can't get work to replace it. I apologize for the time away. I had the Sucuri CloudProxy - Backend Server timeout issue after my last response hung up. Then it wouldn't let me back in from any of the reply links in my email. I forgot to try to go direct to home page but it worked and here I am. So I will try your Winon. As far as I'm concerned you all deserve and get reputation.

    Thank you!!! Your awesome!



    P.S. As mentioned at the start of my post I've got a screen shot of my find cell with format issue after I get this thoroughly resolved by attempting the faster solution. I'll thread that one after a bit in the non VBA forum.

  13. #13
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Thank you for the feedback KG869,

    Glad I could contribute, and thank you also for adding to my Reputation. I really appreciate it!

    Regards.

  14. #14
    Registered User
    Join Date
    07-06-2015
    Location
    Central, Oregon
    MS-Off Ver
    2013
    Posts
    56

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Winon,

    I need help here if you could. I'm not sure what's missing but I get the Run-time error '91 or Object variable or With block variable not set. I attached a screen shot where the code hangs up. Thank you sir.
    Attached Images Attached Images

  15. #15
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Hi KG869,

    I cannot replicate your problem.

    Do you perhaps have other macros with the same name in your Module? Have you tried resetting the VBE and save the Workbook before trying it again? Please try that quickly, while I hang around.

    Thank you.

  16. #16
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    @ JOHN H. DAVIS,

    Did you perhaps experienced the same issue?

    Thank you.

  17. #17
    Registered User
    Join Date
    07-06-2015
    Location
    Central, Oregon
    MS-Off Ver
    2013
    Posts
    56

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    I reopened it and now the worksheet wont' come up even after trying arrange all tiled. I can get to the VB script since the command header is visible. I'm working to get it back.

  18. #18
    Registered User
    Join Date
    07-06-2015
    Location
    Central, Oregon
    MS-Off Ver
    2013
    Posts
    56

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    @ Winon,
    I am going to have to rebuild the sheet. It's corrupt somehow. I'll copy the code and retry your code and report back. If you could check back next opportunity sir I may then have an update available.

  19. #19
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Thank you KG869,

    In the meantime please see the problem free attachment.

    'Till later then.
    Attached Files Attached Files

  20. #20
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    That problem in Winon's code would happen if there are no blank cells found, then it tries to activate nothing.
    Last edited by Arkadi; 02-08-2017 at 04:37 PM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  21. #21
    Registered User
    Join Date
    07-06-2015
    Location
    Central, Oregon
    MS-Off Ver
    2013
    Posts
    56

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Winon,

    Yes it was very fast. Amazingly different. Only issue is it turned every cell in the range green and filled it with 1s. Not exactly what I had in mind BUT it was very fast! lol. Ok I will go back to the slow code for now and see if I can figure out how it did that and learn something. Thank you sir.

  22. #22
    Registered User
    Join Date
    07-06-2015
    Location
    Central, Oregon
    MS-Off Ver
    2013
    Posts
    56

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    @Arkadi,

    Thanks for the insite. Maybe I'll look at it again and see why that is. Thank you sir.

  23. #23
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Hello KG869,

    Yes, I found the same hilarious issue. Fast but maybe too fast!LOL

    My initial code became unstable and unreliable cause I tried to keep it short, and in the process, came short myself. OUCH!!!

    Stop laughing please, it hurts man!

    Please try the revised attachment now, which sports the Code below;

    Please Login or Register  to view this content.
    The real culprit was this line below:

    Please Login or Register  to view this content.
    Kind regards.
    Attached Files Attached Files
    Last edited by Winon; 02-09-2017 at 08:39 AM. Reason: Fixed Code and attachment

  24. #24
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    @Arkadi,

    That problem in Winon's code would happen if there are no blank cells found, then it tries to activate nothing.
    Be careful. Very careful with your wild accusations.

    Have you tried my new revised attachment?

    Thank you for your input here my friend, I appreciate it!

    See my reply in the Post above, which could hold true to your observation with my previous attempts.

    Kind Regards.

  25. #25
    Registered User
    Join Date
    07-06-2015
    Location
    Central, Oregon
    MS-Off Ver
    2013
    Posts
    56

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Winon,

    The new code worked wonderfully well!! It is very fast and I am very glad to get past slow mode code. Thanks so much for your help and contribution to solving my code problem. I think I understand what it is doing. It is amazing the number of ways the code can be written. Thanks for helping me learn.


    I would like to see search and replace work as intended it would have saved a lot of effort from everyone but there's a challenge and a laugh in every opportunity.


    Also thanks again to all other contributors!

    @JOHN H. DAVIS , @YasserKhalil , @Arkadi

  26. #26
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    @Winon
    Nice solution my friend! It simply ocurred to me that it is hard to activate nothing, as you yourself pointed out... my only "accusation" is that you are brilliant (usually)

    KG869, thanks for acknowledging all the posters, very considerate

  27. #27
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: VBA macro find blank RGB(0, 255, 0) colored cells in range and put in 1 value

    Hi KG869,

    Thank you for the positive feedback, and kind words, glad I could be of some help!

    @Arkadi,

    Please get lost! You have hurt my feelings beyond repair.

    Thank you for the kind acknowledgement of my contribution my friend, and the "Rep". It is much appreciated!

    Best Regards to all of the participants in this Thread.

+ 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. Find Range of blank cells
    By julhs in forum Excel General
    Replies: 7
    Last Post: 02-04-2017, 11:14 PM
  2. Replies: 1
    Last Post: 11-09-2013, 02:43 AM
  3. [SOLVED] Find first and last cell of colored range and put in data
    By moosmahna in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-21-2013, 06:26 AM
  4. [SOLVED] Find the sum of all colored cells
    By skip2mylew in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 01-14-2013, 11:44 PM
  5. VBA code to find blank cells within a range
    By pcbpinoy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-28-2011, 12:24 AM
  6. Find all colored cells
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 08-29-2011, 05:13 AM
  7. [SOLVED] find range of non-blank cells in colum
    By DJS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-26-2006, 05:30 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