Solved

Pop-Up alert in Excel

Posted on 2011-02-25
6
568 Views
Last Modified: 2012-05-11
Is it possible to create a pop-up in excel if a certain cell doesn't contain a value if a certain other cell contains a value?
Let's say
Cell A1 is called "Sales", Cell A2 in called Man hours. Sales is entered to Cell B1, man hours to cell B2. What I want is a pop up alert if Cell B2 is empty if Cell B1 contains a value.
0
Comment
Question by:Brasch
  • 4
  • 2
6 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34985328
Is this what you want?

Sample Attached. Enter a value in B1 and it will promt like you wanted.

Code Used

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Not Intersect(Target, Range("B1")) Is Nothing Then
        If Len(Trim(Target.Value)) <> 0 Then
            If Len(Trim(Target.Offset(1).Value)) = 0 Then _
            MsgBox "Please input man hours"
        End If
    End If
    Application.EnableEvents = True
End Sub

Open in new window

Sample.xls
0
 

Author Comment

by:Brasch
ID: 34985358
That would probably do, but quite annoying in the long run - these things are only invented for people not filling out the forms - for the ones actually doing it right that would be very annoying. If possibly (I have no idea if it is) the perfect solution would be a pop-up when saving. A polite reminder, but when not entering info, it should be a concious choice. Still not being able to save anyway would be a bug. I see how the message is changed, but the best would be "Are you sure you want to continuing without entering man hours?" upon saving
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34985365
1) Instead of showing a popup, use a comment.
2)  Do you want to disable save if one of them is empty?

Sid
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 30

Accepted Solution

by:
SiddharthRout earned 500 total points
ID: 34985388
Here is an example. Upon Saving the file It will prompt if one of them is filled and the other is empty and it won't allow you to save the file till the time both are empty or both are filled. I am also using comments so the users don't get annoyed.

Code Used

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If Not Len(Trim(Sheets("temp").Range("B1").Value)) = 0 And _
    Len(Trim(Sheets("temp").Range("B2").Value)) = 0 Then
        MsgBox "Please fill the Sales/Man hours"
        Cancel = True
    End If
End Sub

Open in new window


Sid
Sample.xls
0
 

Author Comment

by:Brasch
ID: 34985409
As far as I know comments are "onMouseOver", that wouldn't work for an alert

Disabling save would be a bad choice, since both the sales and man hours are based on computer systems and they tend to break down now & then - still sales could be entered after closing and saved before everybody stops working, hence man hours are still ticking. An alert upon saving would be the best, but your first example could work if that's not possible, this is a simplified example, so it would have to be modified to come up with more alerts based upon the same cell
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34985431
As far as I know comments are "onMouseOver", that wouldn't work for an alert

Not necessarily. You can show them permanently.

An alert upon saving would be the best, but your first example could work if that's not possible,

If that is the case then delete the line "Cancel = True" and it will let you save after showing the POP UP

Sid
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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
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 Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
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…

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