+ Reply to Thread
Results 1 to 5 of 5

naming Command Button caption in VBA

  1. #1
    Forum Contributor
    Join Date
    08-20-2012
    Location
    London,England
    MS-Off Ver
    Excel 2010
    Posts
    184

    naming Command Button caption in VBA

    Hi, struggling a bit with the below code.

    The VLOOKUP bit works fine. The issue I have is if I delete the contents of "C15", The previous VLOOKUP result remains as a caption instead of renaming the caption to "Blank"

    Please Login or Register  to view this content.
    Any help would be greatly appreciated.

    MTIA

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: naming Command Button caption in VBA

    But ... do you call the piece of code you presented above after deleting C15?

    May be you shall update button caption every time C15 changes.
    If so, use Worksgeet_Change event code in your sheet (the one where C15 is located) to call procedure writing new cation to Button24 (the snippet above).
    Best Regards,

    Kaper

  3. #3
    Forum Contributor
    Join Date
    08-20-2012
    Location
    London,England
    MS-Off Ver
    Excel 2010
    Posts
    184

    Re: naming Command Button caption in VBA

    Dear Kaper,

    Many thanks for your response. What is bizarre is that it is part of a worksheet change event already. see below. It just doesn't change back....

    [CODE][/Private Sub Worksheet_Change(ByVal Target As Range)
    'ActiveSheet.Protect UserInterfaceOnly:=True

    With Application
    .ScreenUpdating = False
    ' disable events
    .EnableEvents = False
    End With
    On Error GoTo here

    If Range("J73").Value >= 100000 Then CommandButton24.Visible = True
    If Range("J73").Value < 100000 Then CommandButton24.Visible = False
    ActiveSheet.CommandButton24.Caption = Application.WorksheetFunction. _
    VLookup(Range("C15").Text, Worksheets("PSL Vendors").Range("B2:J2000"), 9, False)
    If Range("C15").Value = "" Then ActiveSheet.CommandButton24.Caption = "Blank"CODE]

    MTIA

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: naming Command Button caption in VBA

    Hi,

    Here you have shown that you are disabling events processing:
    Please Login or Register  to view this content.
    Where you enable it back?

    Is it after label here:?

  5. #5
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: naming Command Button caption in VBA

    Please Login or Register  to view this content.
    If C15 is blank, the VLOOKUP will fail and goto the label here ... so that's where you need to check the value of C15

+ 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. Setting Command Button caption
    By pjwhitfield in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-06-2014, 05:11 PM
  2. Command Button Caption
    By tapsmiled in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-23-2014, 09:57 PM
  3. Command Button Caption Wrap
    By DCSwearingen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-27-2008, 10:09 AM
  4. Changing the caption of a Command Button
    By Colin M in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-02-2007, 12:24 PM
  5. using vba to change command button caption
    By PaulaO in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2006, 02:40 PM
  6. [SOLVED] changing the caption of a command button
    By JWCrosby in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-08-2005, 04:15 PM
  7. Command Button Caption
    By Qaspec in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-27-2005, 12:06 PM

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