+ Reply to Thread
Results 1 to 3 of 3

Need help with amending code

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-18-2012
    Location
    new york
    MS-Off Ver
    Office 365
    Posts
    177

    Need help with amending code

    I have the below code to hide a chart when there is no value in A1. The problem I have is A1 is actually a formula =IF(Sheet1!a2<>"",Sheet1!a2,"")
    so it does not work when A1 is "blank". I need the chart to be hidden when the formula generates a blank and visible when the formula generates a value (sheet1 a2).
    FYI i have 20 charts with 20 corresponding cells!

    Can anyone help me fix the code?
    Private Sub Worksheet_Change(ByVal Target As Range)
        
        If Not Intersect(Range("A1"), Target) Is Nothing Then
            Me.ChartObjects("Chart 1").Visible = Range("A1").Value <> ""
        End If
        
    End Sub
    Last edited by Leith Ross; 03-19-2013 at 11:52 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Need help with amending code

    Hello ea223,

    Since the blank is an ambiguous condition indicating the cell may be blank because of the formula result or no formula at all, you can test if the cell has formuila as shown below...
    Private Sub Worksheet_Change(ByVal Target As Range)
        
        If Not Intersect(Range("A1"), Target) Is Nothing Then
            Me.ChartObjects("Chart 1").Visible = (Range("A1").Value <> "" And Range("A1").HasFomula)
        End If
        
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    10-18-2012
    Location
    new york
    MS-Off Ver
    Office 365
    Posts
    177

    Re: Need help with amending code

    Hey, thanks but I am now getting the message 'object doesn't support this property or method' and it does not hide the chart when the formula in cell a1 produces a blank value? any ideas??
    thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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