+ Reply to Thread
Results 1 to 5 of 5

If cell is 0 / empty / has 1 space, then hide pictures.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-24-2004
    MS-Off Ver
    Excel 2013 Pro Plus
    Posts
    122

    If cell is 0 / empty / has 1 space, then hide pictures.

    Hello friends, hope all is well!
    Please help me with the code here.

    The code is built to show the pictures based on what is typed in D4.
    Trouble is that when D4 is 0 or empty or has 1 space, the pictures are NOT disappearing.

    I cant figure it out & Thanks a lot in advance!

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error GoTo Terminate
    Call HideEachShape
    
    If Not Intersect(Target, Range("D4")) Is Nothing Then
    
    If Range("D4").Value = "" Then Call HideEachShape
    
    Call HideEachShape
    Select Case Sheets("Report").Range("D4").Value
    
    Case Sheets("Report").Range("D4").Value
    Sheet2.Shapes(CStr(Sheets("Report").Range("D4").Value)).Visible = True
    
    'Sheet2.Shapes("7").Visible = True
    
    End Select
    End If
    
    Exit Sub
    Terminate:
    Call HideEachShape
    End
    End Sub
    Sub ShowEachShape()
    Dim sObject As Shape
    For Each sObject In ActiveSheet.Shapes
    sObject.Visible = True
     Next
    End Sub

    Sub HideEachShape()
    Dim sObject As Shape
    For Each sObject In ActiveSheet.Shapes
    sObject.Visible = False
    Next
    End Sub
    Last edited by countryfan_nt; 01-09-2018 at 11:59 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,487

    Re: If cell is 0 / empty / has 1 space, then hide pictures.

    Could you use a data validation list in D4, then you could use a worksheet_change event, instead of worksheet_selectionChange event.

  3. #3
    Forum Contributor
    Join Date
    06-24-2004
    MS-Off Ver
    Excel 2013 Pro Plus
    Posts
    122

    Re: If cell is 0 / empty / has 1 space, then hide pictures.

    hi and thanks, I did both of your suggestions, but when I clear contents of D4 I.e. press del button on D4, all the picture appear. please help

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,487

    Re: If cell is 0 / empty / has 1 space, then hide pictures.

    Attaching a sample workbook enables others to work on your problem:

    To attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.

    Click on GO ADVANCED and click "manage attachments" to open the upload window.


    To add a file to a post

  5. #5
    Forum Contributor
    Join Date
    06-24-2004
    MS-Off Ver
    Excel 2013 Pro Plus
    Posts
    122

    Re: If cell is 0 / empty / has 1 space, then hide pictures.

    Hello there, and thank you very much!

    after some trial / error I think I finally got it, thank you, and hope somebody benefits from it:

    Option Explicit
    
    Private Sub Worksheet_Calculate()
    If Range("N4").Value = 1 Then
      
    Call HideEachShape
        
    Select Case Sheets("Report").Range("D4").Value
    
    Case Sheets("Report").Range("D4").Value
    Sheet2.Shapes(CStr(Sheets("Report").Range("D4").Value)).Visible = True
    
    'Sheet2.Shapes("7").Visible = True
    
    End Select
      
       Else
       
    Call HideEachShape
       End If
    End Sub
    Sub ShowEachShape()
    Dim sObject As Shape
    For Each sObject In ActiveSheet.Shapes
    sObject.Visible = True
     Next
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to find last cells in a column (ignoring empty space in a cell)?
    By niuyuer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2016, 03:36 PM
  2. [SOLVED] When Cell does not have 20 letters then add empty space to count 20
    By Anto_BT in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-12-2015, 07:46 AM
  3. [SOLVED] How to remove empty space, unable to make pvot, because pvot calculate empty space
    By vengatvj in forum Excel Charting & Pivots
    Replies: 20
    Last Post: 10-29-2013, 12:43 PM
  4. Hide data labels on the x-axis that represent value of 0 (i.e. remove empty space)
    By lionlunatication in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2013, 10:58 AM
  5. How to remove Empty Space in the Cell
    By ramki in forum Excel General
    Replies: 2
    Last Post: 06-27-2008, 04:27 AM
  6. Replies: 6
    Last Post: 07-05-2005, 12:05 PM
  7. Space between data series (with pictures)
    By dan77 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 04-14-2005, 08:58 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1