Macro to hide shapes of they have no data in them?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I want to set up a set of shapes that can operate like buttons,
The idea is you choose a make from a drop down, then you get a grid of options to press that are all shapes each with a different option,

So What i have are 70 shapes call Bttn1 to Bttn70
each shape is linked to a cell,
I only want the shape to be visable if the cell contains a word,
the cells are a grid not just a row or column,
so I feel I making this more complex than it needs to be,

So Data is in range O12:U22 (with O12 being data for Bttn1, U22 Bttn70 going right to left)

So All I need is a macro that says goto through each cell in range O12:U22 if cell is empty then bttn1 hidden if not bttn1 visible.

any ideas how to do this?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
try this:
VBA Code:
Sub testbtHide()
    Dim i As Long, j As Long, k As Long, nr As Long, nc As Long
    Dim rng As Range, cc As Range
    
    Set rng = ActiveSheet.Range("O12:U22")
    nr = rng.Rows.Count
    nc = rng.Columns.Count
    
    k = 0
    
    With ActiveSheet.Shapes
        For i = 1 To nr
            For j = 1 To nc
                k = k + 1
                Set cc = rng.Cells(i, j)
                .Range(Array("Bttn" & k)).Visible = Not IsEmpty(cc.Value)
            Next j
        Next i
    End With
    Set rng = Nothing
    Set cc = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,973
Messages
6,122,534
Members
449,088
Latest member
RandomExceller01

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