Check Box to highlight row

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,434
Hello Guys,

I found the following code on this forum
Public Sub CB_Read()

Dim oShape As Shape
Dim oTarget As Range

Set oShape = ActiveSheet.Shapes(Application.Caller)
'Change the "Offset(Row,Column)" in the next line to whatever cell is desired for the status of the checkbox.
Set oTarget = oShape.TopLeftCell.Offset(0, -4)

If oShape.ControlFormat.Value = xlOff Then
oTarget.Value = 0
Else
oTarget.Value = 1
End If

End Sub

I tried to change it to
Public Sub CB_Read()

Dim oShape As Shape
Dim oTarget As Range

Set oShape = ActiveSheet.Shapes(Application.Caller)
'Change the "Offset(Row,Column)" in the next line to whatever cell is desired for the status of the checkbox.
Set oTarget = Range(oShape.TopLeftCell.Offset(0, -4),oShape.TopLeftCell.Offset(0, -1))


If oShape.ControlFormat.Value = xlOff Then
oTarget.ColorINdex = xlNone
Else
oTarget.ColorIndex = 20
End If

End Sub

But it is not working. What should I be doing to make it work? I want to highlight the whole four cells i.e. from -4 to -1.

Thanks for your help.

Asad
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi,

Maybe

Code:
If oShape.ControlFormat.Value = xlOff Then
    oTarget.[B]Interior[/B].ColorIndex = xlNone
Else
    oTarget.[B]Interior[/B].ColorIndex = 20
End If

HTH

M.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,682
Members
452,937
Latest member
Bhg1984

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