+ Reply to Thread
Results 1 to 3 of 3

Run Message Box When Header in Table is Changed (VBA Code)

Hybrid View

  1. #1
    Registered User
    Join Date
    08-18-2014
    Location
    USA
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Unhappy Run Message Box When Header in Table is Changed (VBA Code)

    Hello,

    I have this VBA code running in cell A1 which gives you a yes/no message box when you try to change the selected cell. I am trying to have the Target.Address = 'Specific Header Cell in Table' but I am not able to develop the code to do so. Here is the code:

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = "$A$1" Then
           Application.EnableEvents = False
           sMsg = "Are you sure you want to change this value?"
           response = MsgBox(sMsg, vbYesNo)
           If response <> vbYes Then
              Application.Undo
              Application.EnableEvents = True
           Else
              Application.EnableEvents = True
              Exit Sub
           End If
        End If
    End Sub
    The main reason I have this message box is to prevent the user from changing the cell in the table because the titles in the tables are linked to macros. If they are changed, the macros will not run. Also, I am aware there are codenames for the excel sheets in a workbook. If there are codenames for the header titles in an excel table, I could link my macros to the codenames. As a result, I would not need this macro for the message box.

    Any help with this would be greatly appreciated.
    Last edited by JBeaucaire; 08-18-2014 at 06:59 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Run Message Box When Header in Table is Changed (VBA Code)

    Try something like this:
    Private Sub Worksheet_Change(ByVal Target As Range)
        On Error Resume Next
        If Not Intersect(Target, Target.ListObject.HeaderRowRange) Is Nothing Then
           Application.EnableEvents = False
           sMsg = "Are you sure you want to change this value?"
           response = MsgBox(sMsg, vbYesNo)
           If response <> vbYes Then
              Application.Undo
              Application.EnableEvents = True
           Else
              Application.EnableEvents = True
              Exit Sub
           End If
        End If
    End Sub
    多么想要告诉你 我好喜欢你

  3. #3
    Registered User
    Join Date
    08-18-2014
    Location
    USA
    MS-Off Ver
    MS Office 2007
    Posts
    21

    Re: Run Message Box When Header in Table is Changed (VBA Code)

    Hi millz,

    The macro works perfectly! Thanks for the help.

+ 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. Header Column Changed automatically
    By Arputharaj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2013, 08:18 AM
  2. Header/Footer changes when page orientation is changed
    By raperm in forum Word Formatting & General
    Replies: 2
    Last Post: 08-15-2013, 03:01 PM
  3. Undo VBA code repeats only on table header for some reason. Can't figure out why.
    By drew.j.harrison in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2013, 01:44 AM
  4. [SOLVED] suppress the message 'refresh operation changed the pivot table'
    By peterhine21 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-01-2006, 12:35 PM
  5. [SOLVED] Can the header margins be changed in excel
    By cartridgeworld in forum Excel General
    Replies: 2
    Last Post: 01-02-2006, 11:30 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