Err: 50290 on check box (Form control)

stanleytp

New Member
Joined
Apr 12, 2022
Messages
7
Office Version
  1. 2016
Platform
  1. MacOS
Code was working until I tried to call Sub cbMaint_Click for me another Sub cbMaint_btn. Now I am geting a 50290 error on red line. Any thoughts?

How can I streamline this code?



Sub cbMaint_btn()
Dim MaintItems As Range
Set MaintItems = Range("B9:B19")
Call cbMaint_Click(MaintItems)
End Sub


Sub cbMaint_Click(Maintlist As Range)
Dim cell As Range

If Range("A1").Value = "D" Or ActiveSheet.Shapes("cbMaint").ControlFormat.Value = xlOn Then

Range("F9").Interior.ColorIndex = 6

For Each cell In Worksheets("ROM").Range(Maintlist)
'enable Complexity column
cell.Offset(0, 1).Interior.ColorIndex = 6 'yellow
cell.Offset(0, 1).Font.ColorIndex = xlColorIndexAutomatic
cell.Font.ColorIndex = xlColorIndexAutomatic 'black
cell.Offset(0, 1).Value = "None"
cell.Offset(0, 1).Validation.InCellDropdown = True
cell.Offset(0, 1).Validation.ShowError = True

'enable Hours column
cell.Offset(0, 2).Interior.ColorIndex = xlColorIndexNone 'no color
cell.Offset(0, 2).Font.ColorIndex = xlColorIndexAutomatic
"
Next cell
Else

For Each cell In Worksheets("ROM").Range(Maintlist)
cell.Offset(0, 1).Interior.ColorIndex = xlColorIndexNone 'no color
cell.Offset(0, 1).Font.ColorIndex = 15
cell.Font.ColorIndex = 15 'light gray
cell.Offset(0, 1).Value = "None"
cell.Offset(0, 1).Validation.InCellDropdown = False
cell.Offset(0, 1).Validation.ShowError = False

'disable Hours column
cell.Offset(0, 2).Font.ColorIndex = 15 'light gray
Next cell

End If

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi,
untested but see if this update to your code does what you want

VBA Code:
Sub cbMaint_btn()
    Dim MaintItems As Range
    Set MaintItems = ThisWorkbook.Worksheets("ROM").Range("B9:B19")
    Call cbMaint_Click(MaintItems)
End Sub


Sub cbMaint_Click(ByVal Maintlist As Range)
    Dim State       As Boolean
    Dim ws          As Worksheet
    
    Set ws = Maintlist.Parent
    
    State = ws.Range("A1").Value = "D" Or ws.CheckBoxes("cbMaint").Value = xlOn
    
    ws.Range("F9").Interior.ColorIndex = 6
    
    With Maintlist
        With .Offset(, 1)
            .Interior.ColorIndex = IIf(State, 6, xlColorIndexNone)              'yellow / None
            .Font.ColorIndex = IIf(State, xlColorIndexAutomatic, 15)            'Black / Light Gray
            .Value = "None"
            .Validation.InCellDropdown = State
            .Validation.ShowError = State
        End With
        .Font.ColorIndex = IIf(State, xlColorIndexAutomatic, 15)                'Black / Light Gray
        'Hours column
        .Offset(0, 2).Interior.ColorIndex = xlColorIndexNone                    'no color
        .Offset(0, 2).Font.ColorIndex = IIf(State, xlColorIndexAutomatic, 15)   'Black / Light Gray
    End With
    
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,760
Members
449,095
Latest member
m_smith_solihull

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