+ Reply to Thread
Results 1 to 9 of 9

Skip Cells based on colour of cell

Hybrid View

Cremorneguy Skip Cells based on colour of... 08-30-2014, 07:53 AM
pareshj Re: Skip Cells based on... 08-30-2014, 10:25 AM
Vikas_Gautam Re: Skip Cells based on... 08-30-2014, 10:32 AM
HaHoBe Re: Skip Cells based on... 08-30-2014, 10:33 AM
Cremorneguy Re: Skip Cells based on... 08-30-2014, 12:24 PM
Cremorneguy Re: Skip Cells based on... 08-30-2014, 11:28 AM
Cremorneguy Re: Skip Cells based on... 08-30-2014, 12:29 PM
pareshj Re: Skip Cells based on... 09-01-2014, 11:41 AM
Cremorneguy Re: Skip Cells based on... 09-01-2014, 10:16 PM
  1. #1
    Forum Contributor
    Join Date
    07-30-2014
    Location
    Mosman, Australia
    MS-Off Ver
    2013
    Posts
    118

    Skip Cells based on colour of cell

    Hi there,

    I have a macro where it will skip cells that have diagonal lines in the cell. This works well because i use it for data entry and sometimes theres a specific cell i don't need to put data into, therefore i put the diagonal lines in the cell and it will automatically skip the cell when entering the data. The VBA code is as follows:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If ActiveCell.Borders(xlDiagonalDown).LineStyle = xlContinuous Then
            ' Has Line, Select Next Cell
            ActiveCell.Offset(1, 0).Range("A1").Select
        End If
    End Sub
    Now i'm using conditional formatting to highlight these cells in a shade of grey but i can't conditionally format the cell to place the diagonal lines in. Is there a VBA code similar to above where i can have the cell skipped over based on the colour of the cell? The RGB colour of the grey i'm using is:
    R: 128
    G: 128
    B: 128

    Is this possible?

    Thanks
    Last edited by Cremorneguy; 08-30-2014 at 12:23 PM.

  2. #2
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: Skip Cells based on colour of cell

    Hi,

    I have made little changes in your code and hope this is what you want:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If ActiveCell.Interior.Color = RGB(128, 128, 128) Then
    ' Has Line, Select Next Cell
    ActiveCell.Offset(1, 0).Range("A1").Select
    End If
    
    End Sub


    Regards,
    Paresh J
    Click on "* Add Reputation" as a way to say thanks

  3. #3
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Skip Cells based on colour of cell

    Try this..
    I hope this will do...

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Borders(xlDiagonalDown).LineStyle = xlContinuous OR _
       Target.Interior.Color = RGB(128, 128, 128) Then
    ' Has Line, Select Next Cell
    ActiveCell.Offset(1, 0).Range("A1").Select
    End If
    End Sub
    Regards,
    Vikas Gautam
    Excel-buzz.blogspot.com

    Excel is not a matter of Experience, its a matter of Application.

    Say Thanks, Click * Add Reputation

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

    Re: Skip Cells based on colour of cell

    Hi, Cremorneguy,

    Your opening post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    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
    Forum Contributor
    Join Date
    07-30-2014
    Location
    Mosman, Australia
    MS-Off Ver
    2013
    Posts
    118

    Re: Skip Cells based on colour of cell

    Ok i figured out the code thing, hopefully this has adhered to the rules. Apologies.

  6. #6
    Forum Contributor
    Join Date
    07-30-2014
    Location
    Mosman, Australia
    MS-Off Ver
    2013
    Posts
    118

    Re: Skip Cells based on colour of cell

    Ok i figured out the code thing, hopefully this has adhered to the rules. Apologies.
    Last edited by Cremorneguy; 08-30-2014 at 12:25 PM.

  7. #7
    Forum Contributor
    Join Date
    07-30-2014
    Location
    Mosman, Australia
    MS-Off Ver
    2013
    Posts
    118

    Re: Skip Cells based on colour of cell

    Thanks Pareshj,

    This has worked, however only if i select the cell and colour it manually.

    I've currently got the cells that are meant to be grey autosumming from another sheet. I have a conditional format using a formula ='Start'!$A1="X", so anything on the other sheet that has the letter X in the cell will automatically change specific cells on this sheet to grey. I'm using the same colour grey as in the VBA but the VBA won't work with the conditional formatted cells. Is there any way we can get the VBA to work on the conditionally formatted cells?

    Many thanks

  8. #8
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: Skip Cells based on colour of cell

    Hi,

    OfCourse! It will work for conditional formatting too. But you need to check whether you are using correct event as in this case you are using worksheet_selectionchange.


    Regards,
    Paresh J

  9. #9
    Forum Contributor
    Join Date
    07-30-2014
    Location
    Mosman, Australia
    MS-Off Ver
    2013
    Posts
    118

    Re: Skip Cells based on colour of cell

    Hi Paresh,

    I'm not sure how to work it. I've put your code in but it's not working on my excel. I have the conditional format set so the cell colour and text is RGB 128,128,128 but it still doesn't work. Could you please have a look at my attached file and check if i have it set up correctly? It's only set up on the sheet named "1". The conditional format is set to reference cells in column AM, the cells in column AM are actually equalling to cells from sheet named "Start". Not sure if this changes anything.

    Many thanks for your help.

+ 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. Change colour of cells based on another cell's colour (Not value)
    By LTrain89 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-25-2013, 08:44 PM
  2. Highlight or colour a cell or cells based on cells in another range.
    By baffld in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-30-2012, 08:41 PM
  3. Change Colour of 3 Cells based on Value of Other Cell
    By hazza147 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2010, 05:57 AM
  4. Colour Cells based on the value of another cell
    By Macca_GB in forum Excel General
    Replies: 1
    Last Post: 03-27-2010, 03:10 AM
  5. [SOLVED] How do I set a colour to 4 cells based on the value of a cell
    By Andy64 in forum Excel General
    Replies: 1
    Last Post: 09-06-2005, 02:05 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