+ Reply to Thread
Results 1 to 4 of 4

Getting the old value ????

Hybrid View

  1. #1
    Registered User
    Join Date
    07-02-2006
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    23

    Getting the old value ????

    Hi there... Please help me with this...

    I have a sheet (Sheet1) and in A1 the value 150.

    I'm trying to change that value (150), but with a confirmation because that cell will be locked after click "Yes".

    The problem is here: (Using "If MSGBOX") ("Are you sure you want to make this change ?")=NO

    In this case, the value in A1 must return to 150 (the previous value)...

    How can I do that??

    Any help will be very appreciated!


    Very thanks in advance.
    Last edited by socram_06; 11-03-2008 at 10:01 AM.
    Marcos.

  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
    Hello socram_06,

    Do you already have some code written or do you want someone to write a routine to do this? If you have any code wrtitten, please post it.

    Sincerely,
    Leith Ross

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Socram,

    If you are looking for code to do this, you could insert the following into that sheet's code module (right-click on sheet tab and choose 'View Code'). This will ask the user if they really want to change the value in A1 whenever that cell's value changes, and if not it will revert to the previous value.
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ans As String
    Application.EnableEvents = False
        If Target.Address = "$A$1" Then
            ans = MsgBox("Are you sure you want to do this?", vbYesNo, "Warning!")
            If ans = vbNo Then Application.Undo
        End If
    Application.EnableEvents = True
    End Sub

  4. #4
    Registered User
    Join Date
    07-02-2006
    Location
    Brazil
    MS-Off Ver
    2013
    Posts
    23

    Thumbs up

    Hi friends, thank you for reply...

    Here what I was doing...

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Range("A1").Value = "" Then Exit Sub
    
    If MsgBox("Are you sure you want to do this ??", vbYesNo) = vbYes Then
    
    Exit Sub
    End If
    
    'here was the problem !!!
    'Range("A1").Value = ' ?????????
    pjoaquin, your code is perfect for what I need...

    Thank you very much

+ 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