+ Reply to Thread
Results 1 to 12 of 12

Macro: Use cell fill color to determine if to copy & paste to another cell on the same row

  1. #1
    Registered User
    Join Date
    11-19-2012
    Location
    Quantico, VA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Macro: Use cell fill color to determine if to copy & paste to another cell on the same row

    Good Day all,

    Given the example file I'm trying to use VBA to copy and paste values only from column I to the values in column E if:

    1. The cell is green

    That's it. In the actual file there are as many as 10,000 names. some of the cells in that row are red or clear and should not be copied over.

    P.S. Column I is actually column BL and column E is actually column S in the real file I'm working on.

    I'm stuck at work and saw this could be done in my book, but I won't be getting to that book anytime soon. Any help would be much appreciated.

    Best Regards,

    T. Samuels
    Attached Files Attached Files
    Last edited by tsamuels; 05-19-2013 at 04:25 AM. Reason: Greater detail to avoid confusion

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Macro: Use cell fill color to determine if to copy & paste to another cell on the same

    So you Just want to copy the Values without the Cell Color and any other formatting?
    Cheers!
    Deep Dave

  3. #3
    Registered User
    Join Date
    11-19-2012
    Location
    Quantico, VA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Macro: Use cell fill color to determine if to copy & paste to another cell on the same

    Yes. but using a macro

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro: Use cell fill color to determine if to copy & paste to another cell on the same

    Hi, tsamuels,

    you should have indicated that you apply Conditional Formatting for the cell color.

    Please Login or Register  to view this content.
    You would need to adapt the I in Set rngArea for your Column BL instead of I here and change the E to S for the destination.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  5. #5
    Registered User
    Join Date
    11-19-2012
    Location
    Quantico, VA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Macro: Use cell fill color to determine if to copy & paste to another cell on the same

    Holger I ran into one issue,

    Because in the actual file a vlookup pulls up the column I value, I will get a bunch of duplicate values that can be greater than 100. That's why I think it must be done by the cell fill color.

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro: Use cell fill color to determine if to copy & paste to another cell on the same

    Hi, tsamuels,

    maybe thatīs why the code is using CountIf to see if the value in the checked cell is unique in the area to check as well as over 100 before copying?

    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    11-19-2012
    Location
    Quantico, VA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Macro: Use cell fill color to determine if to copy & paste to another cell on the same

    It works like a charm in the example, but when I change the columns in the code to match the actual file I get a error to debug " '1004' no cells were found" The columns have data, (granted its 1100 rows later in row BL). Any suggestions?

  8. #8
    Registered User
    Join Date
    11-19-2012
    Location
    Quantico, VA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Macro: Use cell fill color to determine if to copy & paste to another cell on the same

    I was able to recreate the error in the example file. I'm using a vlookup formula to provide the row I data. this is whats causing the error in the actual file. Can you fix it?
    Attached Files Attached Files

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro: Use cell fill color to determine if to copy & paste to another cell on the same

    Hi, tsamuels,

    SpecialCells(xlCellTypeConstants, 23) is looking for constants in the range, I should have suggested
    Please Login or Register  to view this content.
    which is looking for formulas in the range. I would recommend to use an On Error Resume Next when using SpecialCells to avoid a run-time error and after setting back with On Error GoTo 0 and checking if any error had occurred.

    Ciao,
    Holger

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro: Use cell fill color to determine if to copy & paste to another cell on the same

    Hi, tsamuels,

    if your formulas return a blank cell if nothing is found and cover the entire range itīs quite useless to try and narrow down the area by using SpecialCells with Formulas as all cells would be included. So just the range could be checked without any specialcells being added to it.

    Ciao,
    Holger

  11. #11
    Registered User
    Join Date
    11-19-2012
    Location
    Quantico, VA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Macro: Use cell fill color to determine if to copy & paste to another cell on the same

    Holger your Awesome! I have no ideas how to implement error checking. Id like to learn if your will to teach. It works great. Its just really, really, really, slow. I think is because column a has formulas all the way down to 10,001. The student info is from rows b to f and is actually only at row 3585, but can grow to 10,000. Any advice on how to speed it up? Regardless I considered this thread solved. Thanks for your time!

  12. #12
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro: Use cell fill color to determine if to copy & paste to another cell on the same

    Hi, tsamuels,

    one way to speed the macro up would be to turn off Calculation and ScreenUpdating at the beginning and turn it on again at the end:
    Please Login or Register  to view this content.
    or store the values in Variables and use them instead.

    Another way to narrow down could be an extra column holding a formula and serving as feed for an Autofilter. From your sample workbook I choose Column J and placed the following formula into J2 and then dragged it down (double click on the lower right end of cell J2):
    Please Login or Register  to view this content.
    Autofilter may be used for 1 and will definitely narrow down the number of checks to fulfill if the code is applied to only visible cells via SpecialCells(xlCellTypeVisible) and a check if there are indeed cells to apply the For Each rngCell in rngArea...

    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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