Cell Background Colour Not Being Identified

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Please consider this code:
Rich (BB code):
 Sub singlesegment()
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    With ws_form
        With segtar
            If .Interior.Color = ccgreen Then .Cells.Interior.Color = xlNone
            If .Interior.Color = xlNone Then .Cells.Interior.Color = ccgreen
        End With
    End With
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub

'setgar' is a publicly declared Range variable equal to the value of target acquired in another worksheet's 'SelectionChange' event. With this code, when that cell is selected, I wish to change it's fill colour based on it's state when selected. If the cell interior is green, it clears the cell of any colour. If it's clear of colour, it sets it green. (ccgreen is a custom colour)

However, it's not working. When I step through the code, it fails to identify the colour of the cell interior, so no actions are taken.

Where is my error?
 
I've provided my file for anyone that would like to try it out to see if they can narrow down the issue. Feel free to check it through.
Open file, and complete the login. Employee Number: 00000, password: Demo, Equipment number: 709.
Then click the next series of empty boxes that appear. The last box on MapMe5 is "Submit Accomplishment". Click this.

In the form, click "[01-18]" (cell H8). It will change green. Doing this creates a sublist of "segments" in rows 9 through 18, which are hidden.
To reveal the hidden segment row, press the "[+]" (cell E8). This will reveal the hidden rows. The cells H8-H18 (segement select cells) will be green. They turned green when H8 was clicked.
Press H8 again and all select cells (H8-H18) will turn white.
Press H8 again to toggle them ON (green) again.
Now, click one of the segemnt select cells (H9-H18). My code is supposed to toggle just that segment selection ON (green) and off (white) as it's clicked. In my testing, it isn't.

I hope this helps.

File is here.
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
The problem is that in the "allsegments" code you are only applying the fill colour to col H, but then in the "singlesegment" code you are checking both cols H & I
 
Upvote 0
Thank you Fluff. Normally once you give me the nudge I seem to be able to figure out the solution. This one is kinda evading me.

in the "singlesegment" code you are checking both cols H & I
Is this because it's relying on segtar, a range of $H#:$I# ? If so, how can I reduce "segtar" to just the $H# ? (Assuming of course this is the path to the solution)
 
Upvote 0
You could use
VBA Code:
        With segtar.Resize(1, 1)
in the singlesegment sub
 
Upvote 0
Solution
Thank you so much Fluff, I would never have found the issue let alone the solution. I need to do some research on 'resize'.
You saved my day!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,369
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top