+ Reply to Thread
Results 1 to 7 of 7

Excel VBA Change Event Show/Hide Graphic

Hybrid View

  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    Christchurch, New Zealand
    MS-Off Ver
    2010
    Posts
    43

    Excel VBA Change Event Show/Hide Graphic

    Hi

    I'm trying to show/hide a text box based on a cell value but can't seem to get it to work. The cell value is controlled by Option Buttons.

    This line of code works when I attach to a command button so I must be going wrong with the change event.
    ActiveSheet.Shapes.Range(Array("RoofingTextBox")).Visible = msoTrue
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Application.Intersect(Target, Target.Worksheet.Range("S2")) Is Nothing Then
    
    If ActiveSheet.Range("S2") = 3 Then
    
    ActiveSheet.Shapes.Range(Array("RoofingTextBox")).Visible = msoTrue
    
    Else: ActiveSheet.Shapes.Range(Array("RoofingTextBox")).Visible = msoFalse
    
    End If
    
    End Sub
    Any help would be greatly appreciated.

    Thanks

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    45,270

    Re: Excel VBA Change Event Show/Hide Graphic

    Try:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Application.Intersect(Target, Range("S2")) Is Nothing Then
         If Range("S2") = 3 Then
              ActiveSheet.Shapes.Range(Array("RoofingTextBox")).Visible = msoTrue
         Else
              ActiveSheet.Shapes.Range(Array("RoofingTextBox")).Visible = msoFalse
         End If
    End If
    
    End Sub


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    06-26-2014
    Location
    Christchurch, New Zealand
    MS-Off Ver
    2010
    Posts
    43

    Re: Excel VBA Change Event Show/Hide Graphic

    Hi TMS,

    Still no luck, will keep fiddling!

    Thanks
    Jo

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    45,270

    Re: Excel VBA Change Event Show/Hide Graphic

    Can you post a sample workbook?

  5. #5
    Registered User
    Join Date
    06-26-2014
    Location
    Christchurch, New Zealand
    MS-Off Ver
    2010
    Posts
    43

    Re: Excel VBA Change Event Show/Hide Graphic

    Hi TMS,

    I've uploaded the file I'm working on. I hope you can spot where I'm going wrong, I'm pulling my hair out!

    Thanks
    Jo
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-26-2014
    Location
    Christchurch, New Zealand
    MS-Off Ver
    2010
    Posts
    43

    Re: Excel VBA Change Event Show/Hide Graphic

    Ok so I've discovered that if I manually change the cell rather than it changing via formula it works, so maybe I have to rethink my method! Any suggestions?

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    45,270

    Re: Excel VBA Change Event Show/Hide Graphic

    A Change event only fires if changes are made manually, or by code, not for changes in the value of a formula. You need to monitor the cell's precedents for changes.


    Regards, TMS

+ 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. Hide Columns based on Date value in cell (Worksheet Change event)
    By jstriker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-22-2014, 04:37 PM
  2. [SOLVED] UserForm Change of data value event- Label show or hide
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-16-2014, 11:54 AM
  3. Worksheet Change Event to Show Command Button
    By ker9 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-21-2011, 04:39 PM
  4. [SOLVED] show in a excel graphic a total percentage for 5 diff data fiels
    By Julio in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 09-01-2005, 09:05 AM
  5. [SOLVED] Can't hide/unhide rows under worksheet change event?
    By Don Wiss in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-24-2005, 07:02 PM

Tags for this Thread

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