VBA help - Why am I getting multiple pop-up boxes instead of just 1 when opening workbook??

aliecat08

New Member
Joined
Oct 18, 2017
Messages
14
Office Version
  1. 2013
Platform
  1. Windows
So I had previously posted asking for a code for a pop-up showing upcoming deadlines, but didn't get responses so I tried to come up with my own code. But now, I'm getting multiple pop-ups instead of just one.

I want 1 pop-up that shows the First, Last Name and DOL for each person whose "Statute" is 60 days or less away AND "Status" is Pre-lit. So the message will look like this:

UPCOMING STATUTES:
Jane Doe statute expiring in 20 days
Hotel Doe statute expiring in 59 days

Here is my code:

VBA Code:
Private Sub Workbook_Open()
    Dim bottomG As Integer
    bottomD = Range("D" & Rows.Count).End(xlUp).Row
    Dim c As Range
    For Each c In Range("D2:D4000")
        If c >= Date And c <= Date + 60 Then
            MsgBox c.Offset(0, -2) & " " & c.Offset(0, -3) & " " & "DOL: " & c.Offset(0, -1) & " statute expiring in " & c - Date & " days."
        End If
    Next c
End Sub




Here is my table:
1675122491944.png


Please help!
 
Last edited by a moderator:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Also, when posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug & copy. My signature block below has more details. I have added the tags for you this time. 😊

Try this code instead
VBA Code:
Private Sub Workbook_Open()
  Dim bottomD As Long
  Dim t As String
  
  bottomD = Range("D" & Rows.Count).End(xlUp).Row
  t = "UPCOMONG STATUTES:"
  Dim c As Range
  For Each c In Sheets("OpenCases").Range("D2:D" & bottomD)
    If c >= Date And c <= Date + 60 Then
      t = t & vbLf & c.Offset(0, -2) & " " & c.Offset(0, -3) & " " & "DOL: " & c.Offset(0, -1) & " statute expiring in " & c - Date & " days."
    End If
  Next c
  MsgBox t
End Sub
 
Upvote 0
Thank you!!!

Is there a way to change the font and justification for "UPCOMING STATUTES:". I'd like it to be red and in the center of the message box.
 
Upvote 0
Thank you!!!
You're welcome.

Is there a way to change the font and justification for "UPCOMING STATUTES:". I'd like it to be red and in the center of the message box.
No. At least not without a lot of effort (look here for example at the complexity of altering features of a standard MsgBox)
You could instead consider designing a pop-up UserForm instead, though that is not the sort of question I usually get involved in.
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,812
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top