Solved

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

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

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 45

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

708 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

12 Experts available now in Live!

Get 1:1 Help Now