Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-09-18
4
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 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 49

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

715 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