Linking multiple cells

Slywalker

New Member
Joined
Jan 26, 2017
Messages
6
I'm a total noob at vba, so forgive me if this is a simple fix.

Last time I were here, I got some nice person to help me with this:
Code:
Sub ToggleGrey()
    Dim ChkBox As Excel.CheckBox
        Set ChkBox = ActiveSheet.CheckBoxes(Application.Caller)
        With Range(ChkBox.LinkedCell).Offset(0, 1).Resize(1, 7).Interior
            If ChkBox.Value = xlOn Then
                 .ColorIndex = 16
            Else
                 .ColorIndex = xlColorIndexNone
            End If
        End With
End Sub

Just a 'simple' sub to grey out the line of cells that have been toggled by checkbox.

I would like to change this to toggle multiple lines with 1 checkbox. Say, if my checkbox is linked to A32:A35. My original assumption were that I could fiddle with the Offset, but I can't figure out how, without being forced to make a new sub for each specific amount of lines, I would like to effect.

Please don't just give me the correct answer. I'd love to be able to understand why as well.

Thanks in advance
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Yea, I fiddled around with that for a bit. As far as I can tell, that would require me to make multiple subs, if next checkbox is 5 rows. I was hoping I could tie the length to the linked cells directly.

Thanks for the input tho :)
 
Upvote 0
Linking the checkbox to A32:A35 doesnt help, but when you enter the number of wanted lines in the alternative text of the checkbox this wil help:


Code:
Sub ToggleGrey()
    Dim ChkBox As Excel.CheckBox
        Set ChkBox = ActiveSheet.CheckBoxes(Application.Caller)
        X = ChkBox.ShapeRange.AlternativeText
        With Range(ChkBox.LinkedCell).Offset(0, 1).Resize(X, 7).Interior
            If ChkBox.Value = xlOn Then
                 .ColorIndex = 16
           Else
                 .ColorIndex = xlColorIndexNone
            End If
        End With
End Sub
 
Last edited:
Upvote 0
Oh yes! This is exactly what I were looking for! Thanks a bunch

Small side note, before I go changing the other 30 checkboxex alternative text to 1. Is there a way I can say "If nothing in alternate text, set X to 1"?
 
Upvote 0
Code:
Sub ToggleGrey()
    Dim ChkBox As Excel.CheckBox
        Set ChkBox = ActiveSheet.CheckBoxes(Application.Caller)
        If ChkBox.ShapeRange.AlternativeText = "" Then
            X = 1
        Else
            X = ChkBox.ShapeRange.AlternativeText
        End If
        With Range(ChkBox.LinkedCell).Offset(0, 1).Resize(X, 7).Interior
            If ChkBox.Value = xlOn Then
                 .ColorIndex = 16
               X = ChkBox.ShapeRange.AlternativeText
            Else
                 .ColorIndex = xlColorIndexNone
            End If
        End With
End Sub
 
Last edited:
Upvote 0
*facepalm*
Now I feel like an idiot. Don't know why I expected some voodoo magic, instead of an If argument.

Thank you so much for all the help. I really appreciate it
 
Upvote 0

Forum statistics

Threads
1,224,755
Messages
6,180,751
Members
452,996
Latest member
nelsonsix66

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