+ Reply to Thread
Results 1 to 6 of 6

Worksheet Change Event to Show Command Button

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Worksheet Change Event to Show Command Button

    I can't get this to work, any guidance? If the target is not blank (it starts out blank, then show the button. (I've reworked this in multiple ways and can't come up with the correct language)

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If Not Intersect(Range("Approved"), Target) Is Nothing Then
            If Not Range("Approved") = "" Then
                    cbtEmailMgr.Visible = True
        End If
        
    End If
    
    End Sub
    Thanks!
    Last edited by ker9; 03-21-2011 at 04:36 PM.

  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,258

    Re: Worksheet Change Event to Show Command Button

    Hello ker9,

    I would help to know a few more things. What error message are you getting? Is cbtEmailMgr on the same worksheet as the Worksheet_Change event code? Is this a Forms control, ActiveX control (ControlToolbox), or a Shape?
    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
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Re: Worksheet Change Event to Show Command Button

    Hi, Leith,
    Thanks for responding. This is an ActiveX command button and it is on the same sheet as the change event.
    Generally I'm not getting an error message, it just isn't working right. I've been trying a 1,000 different renditions. Currently, I have the code below. The problem with this version is that when cell C14 (just above) is changed and the user hits return to drop to the C15 cell, the event fires and shows the button. But I don't want to see that button until something is typed into Cell C15 (which is merged C15:E15 and named Approved).

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If Target.Address = Range("C15:E15").Address Then
        If IsEmpty(Range("C15:E15")) Then
            Exit Sub
        Else
            cbtEmailTeam.Visible = True
        End If
    End If
    
    End Sub

  4. #4
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Re: Worksheet Change Event to Show Command Button

    This code is telling me that the cell is not blank, but there is nothing in it so I guess that is part of my problem

    [CODESub IsItBlank()
    If IsEmpty(Range("C15:E15")) Then
    MsgBox "It's blank"
    Else
    MsgBox "NOT blank"
    End If[/CODE]

  5. #5
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    278

    Re: Worksheet Change Event to Show Command Button

    I think I've got it - I unmerge the range and checked each cell - they were all blank.

    I re-merged it and now it's working with this code: (I don't understand it)

    If IsEmpty(Range("approved")) Then
            Exit Sub
        Else
            cbtEmailTeam.Visible = True
        End If

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

    Re: Worksheet Change Event to Show Command Button

    Hello ker9,

    The IsEmpty function will only check a single cell. To check if a range is empty, you can use the WorksheetFunction.CountA function, like this...
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        If WorksheetFunction.CountA(Range("C15:E15")) =  0 Then
           Exit Sub
        Else
            cbtEmailTeam.Visible = True
        End If
    
    End Sub

+ 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