Solved

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

Posted on 2014-09-18
4
220 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now