Results 1 to 20 of 20

Toggle cell fill

Threaded View

  1. #1
    Registered User
    Join Date
    09-08-2012
    Location
    RTP, NC
    MS-Off Ver
    Excel 2010
    Posts
    14

    Toggle cell fill

    I have a relatively small range of data that I want to sort on two criteria using a command button. The criteria are cell fill and numeric value; sorting the filled cells first to the top (actually white cells to the bottom), and then sorting the two groups numerically individually. I was able sort the multiple columns of data with no problem using the macro recorder to obtain the code. I know it has lots of extra words and lines, but that's OK for now.

    However, what I thought would be the easy part, I can not get to work.

    I want to quickly toggle between white fill and a color fill in cells by simply clicking on a cell in the column used for the sort. (I did have all cells involved filled with either white or the color when tested.)

    There are actually two ranges on my worksheet that use different colors for sorting different data, and I don't want this color change to happen anywhere else on the worksheet, so I assumed it was best to define the range involved for each separate color.

    This is what I came up with:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    Range ("G9:G23")
        If ActiveCell.Interior.Color = RGB(255, 255, 255) _
        Then ActiveCell.Interior.Color = RGB(150, 200, 255)
        End Sub
        Else
        If ActiveCell.Interior.Color = RGB(150, 200, 255) _
        Then ActiveCell.Interior.Color = RGB(255, 255, 255)
    End If
        
    End Sub
    What I get when I try to use it is this message:

    "Compile Error
    Invalid Use of property"

    and the "Private Sub" line turns yellow and the"Range" word is surrounded by black.

    And then the command button sorting code no longer works until I delete this code.


    Moderator Edit:

    Welcome to the forum.

    Please notice that code tags have been added to your post. The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at the top of the page and read Rule #3.
    Thanks.
    Last edited by Cutter; 09-08-2012 at 02:32 PM. Reason: Added code tags

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