+ Reply to Thread
Results 1 to 5 of 5

advisory pop up choice

Hybrid View

  1. #1
    Registered User
    Join Date
    07-01-2008
    Location
    Wales, UK
    Posts
    29

    advisory pop up choice

    Hi all

    I've done a search for this one but the more I read the more head scratching I did, so was hoping you could assist.

    Here's my code-

    Sub Save1()
    '
    ' Save1 Macro
    ' Macro recorded 22/03/2008 by Chuckles
    '
    
    '
        Application.ScreenUpdating = False
        Sheets("Project").Range("B2:J10").Copy
        Sheets("Saved").Range("B2").PasteSpecial Paste:=xlValues
        Application.CutCopyMode = False
        Range("L2").Select
        End Sub
    Here's my query:-

    In time I'm going to need an advisory popup to notify the user that I they save here and there's already existing data then the new data will replace the old one if they continue, or something similar.

    In the interim I am happy for a popup to say that data may already exist - continue? Follow by a yes/no or yes/cancel option

    Any thoughts?

    Many thanks.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    Use the Workbook BeforeSave event and put a vbYesNoCancel Message Box in there. Use the return value of the Message Box to determine whether the Save event continues.

    HTH

  3. #3
    Registered User
    Join Date
    07-01-2008
    Location
    Wales, UK
    Posts
    29
    Sounds like a plan, time to google

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    try this

    Option Explicit
    
      Sub Save1()
    
        If Application.WorksheetFunction.Count(Sheets("Saved").Range("B2:J10")) > 0 Then
            Select Case _
                   MsgBox("Data may exist in the target range. Continuing will overwrite this data. Continue?", _
                          vbYesNo Or vbExclamation Or vbDefaultButton1, "Data alert...")
    
                Case vbYes
                    Sheets("Saved").Range("B2:J10").Value = _
                    Sheets("Project").Range("B2:J10").Value
                Case vbNo
                    Exit Sub
            End Select
            End If
        End Sub
    Last edited by royUK; 07-08-2008 at 11:00 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    07-01-2008
    Location
    Wales, UK
    Posts
    29
    That's great work, thank you.

    I added an Else command to it though as nothing happened if the place where the data was being saved to was emply but hope I did your code justice and not done it the wrong way.

      Sub Save1()
    
        If Application.WorksheetFunction.Count(Sheets("Saved").Range("B2:J10")) > 0 Then
            Select Case _
                   MsgBox("Data exists in the target range. Continuing will overwrite this data. Continue?", _
                          vbYesNo Or vbExclamation Or vbDefaultButton1, "Data alert...")
    
                Case vbYes
                    Sheets("Saved").Range("B2:J10").Value = _
                    Sheets("Project").Range("B2:J10").Value
                Case vbNo
                    Exit Sub
            End Select
            Else
                Sheets("Saved").Range("B2:J10").Value = _
                Sheets("Project").Range("B2:J10").Value
                    MsgBox ("Your data has been saved to an empty location. ")
            End If
        End Sub
    I did have a go at it but it was not as detailed or defined as your so big thanks for the code

    Mine ended up something like this before I replaced it with yours.

        YesNo = MsgBox("If your happy to carry on click Yes", vbYesNo + vbQuestion, "You may be about to save over old data.")
            Select Case YesNo
                Case vbNo
                    Exit Sub
            End Select
        Application.ScreenUpdating = False
        Sheets("Project").Range("B2:J10").Copy
        Sheets("Saved").Range("B12").PasteSpecial Paste:=xlValues
        Application.CutCopyMode = False
        Range("L2").Select
    The range is slightly different as there are 5 save options available, I dare say it could be done with better coding for the 5 but at least I can follow this way LOL.

    Not quite what I wanted but it was a new piece of code for me

+ 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