Solved

VBA to prevent save if conditional flag exists in column i15 - i84

Posted on 2014-09-18
4
221 Views
Last Modified: 2014-09-18
This is what I have so far. Seems simple but can not figure out the range so the code scans column i15 - i84 for a value. If value is detected then a message comes up and save is not allowed until flag is removed. Currently only works for i15. Have tried $i15 thinking that would cover the entire column with no luck.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

If Sheets("Form").Range("i15").Value = "l" Then
  MsgBox "Mandatory Field Alert!! You must complete 'Employee Needing Coverage' field before save can be performed, vbInformation"
 Cancel = True
End If
End Sub


Image included to show layout of form and flag
image.jpg
0
Comment
Question by:Walter Williams
  • 2
  • 2
4 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40331444
    Dim rngFound As Range
    Range("I15:I84").Select
    Set rngFound = Selection.Find(What:="l", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True _
        , SearchFormat:=False)
    If Not rngFound Is Nothing Then
        MsgBox "Mandatory Field Alert!! You must complete 'Employee Needing Coverage' field before save can be performed, vbInformation"
    End If
 Cancel = True

Open in new window

0
 

Author Comment

by:Walter Williams
ID: 40331561
MartinLiss,

That did it, works perfectly.. Thank you..
0
 

Author Closing Comment

by:Walter Williams
ID: 40331563
Very quick response...  thank you again, worked perfectly...
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40331575
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question