Home » excel » vba – Checkbox placement issue while filtering data in protected worksheet excel

vba – Checkbox placement issue while filtering data in protected worksheet excel

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a protected worksheet, with cell protection as both Locked and Hidden. In first column I have Check Box (Form Control) against each row.

Unfiltered Data

Problem is when I try to filter data, there is a extra check box in last row.
Filtered Data

I tried linking cell to check box and enabled option ‘Move but don’t size with cells’ but still behavior is same. Is there a way to resolve this?

How to&Answers:

well seems like checkboxes are bad guys

but there’s a prison even for them

  • make sure your sheet has at least one cell that calculates

  • make sure each checkbox is completely inside its cell, i.e. its
    borders (which appear at selecting it) must entirely fall within the cell
    where you chose it to be

  • set your sheet calculation as “automatic” (Formulas->Calculation Option-> Automatic)

  • place the following code in the sheet code pane

    Private Sub Worksheet_Calculate()
        Dim shp As Shape
    
        For Each shp In Me.Shapes
            shp.Visible = shp.TopLeftCell.EntireRow.Height <> 0
        Next
    End Sub