Click check box and fill range of cells with RED

lockarde

Board Regular
Joined
Oct 23, 2016
Messages
77
Good morning all,

I have a workbook that tracks ongoing jobs. I have a sheet for each month that tracks jobs requested during that time period. There are times when a job gets put on hold, and I'd like to have an "On Hold" checkbox that when I click it, it sets the fill color of the range of cells associated with that job to turn red. I have some basic code written, but am getting Subscript out of range error.
VBA Code:
Sub Hold1_Click()

    With Sheet9
    Range("A4,T6").Interior.ColorIndex = RGB(255, 0, 0)
    End With

End Sub

This is sort of just a proof of concept, the range "A4:T6" is typically the range size of one job, however, sometimes there are extra rows included in the range due to extra "Notes". So ideally, I would have a checkbox next to each job, and it'd be able to find the end of the job, and color the range red (with the inverse being true as well, once a job is no longer on hold, unchecking the box would revert the format back to its original state). Some jobs have 3 or 4 rows of "notes", typically jobs only have 1 row of notes.

A typical job looks like the following:
1582915817964.png


Any help is greatly appreciated!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
How about
VBA Code:
Sheet9.Range("A4,T6").Interior.Color = RGB(255, 0, 0)
or
VBA Code:
Sheet9.Range("A4:T6").Interior.Color = RGB(255, 0, 0)
 
Upvote 0
Thanks for your reply Fluff! I was writing a reply as your response came in - I got the same code you posted, and it works great! Could you help with "undoing" that fill when I uncheck the box? I'm not sure how to track the previous formatting in order to revert it back once the job is no longer on hold
 
Upvote 0
I'm using something similar to the second version you posted,
VBA Code:
Sub Hold1_Click()

    With Sheet9
        .Range("A4:T6").Interior.Color = RGB(255, 0, 0)
    End With
    
End Sub
 
Upvote 0
Thinking about it are you using a Form Control checkbox, or an ActiveX one?
And is it on Sheet9?
 
Upvote 0
It's an ActiveX checkbox, and it is on Sheet9. Eventually, I'd like to have a checkbox for each job - and that's where it gets tricky if the job has more than the typical 3 rows, and the number of jobs fluctuates month to month.
 
Upvote 0
Rather than adding/deleting checkboxes depending on the number of jobs, how about using a doubleclick event.
So, for instance you doubleclick A4 & the cells turn red?

Can you post some sample data using the XL2BB add-in that shows jobs with variable number of rows?
 
Upvote 0
This will work for your current setup.
VBA Code:
Sub Hold1_Click()
   Dim Clr As Long
   With Sheet9
      If .Hold1.Value Then
         Clr = .Range("A4").Interior.Color
         .Range("A4:T6").Interior.Color = RGB(255, 0, 0)
         .Range("A4").Interior.Color = Clr
      Else
         .Range("A4:T6").Interior.Color = Clr
      End If
   End With
End Sub
I have left A4 with the current fill as it needs to be stored somewhere, but it can be changed to another cell
 
Upvote 0
I actually like the double-click idea alot, that way I don't have to keep adding a checkbox for each new job. It took me a second to get the XL2BB all sorted, but the following is what I captured, with sensitive information removed. I'm not sure why the columns became so large? I put a screenshot at the bottom so you can see what it looks like for me.

Daily Engineering Reporting.xlsm
ABCDEFGHIJKLMNOPQRST
1 Engineering Request DesignsTotal Engineering requests Sheet1: 2TOTAL WORKDAYS:22Completed Engineering requests Sheet1: 0/2
2Updated on: 2/28/202012:52 PM
3Item(s)LocationEmployeeJob IDCompany Job Value Net Price Est HoursAct HoursRequest DateComp DateLWHQty.StyleMil Spec?Prod Job?Concept?Design/BOM?
4Item 1
5Notes:Standard request, one note with basic job details. Job completed with no updates/change orders required. Completeion date gets filled in and counters at top track
6
7Item(s)LocationEmployeeJob IDCompany Job Value Crate Price Est HoursAct HoursRequest DateComp DateLWHQty.Crate StyleMil Spec?Prod Job?Concept?Design/BOM?
8Item 1
9Notes:Initally starts as standard request
10Notes:As job progress, notes possibly added detailing communication with customer
11Notes:Last note on a job such as this states current "status" of job. i.e "Customer requested changes - conference call scheduled 3/2/20"
Sheet1
Cell Formulas
RangeFormula
F1F1="Total Engineering requests " & MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255) & ": "
I1I1= COUNTIF(A:A,A4)
M1M1=NETWORKDAYS(V8,EOMONTH(V8,0))
P1P1="Completed Engineering requests " & MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255) & ": "
T1T1=COUNT($K:$K)&"/"&I1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
T1Expression=COUNT($K:$K)=$I$1textNO
T1Expression=COUNT($K:$K)<$I$1textNO


1582919966951.png
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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