BoffleHoffer
New Member
- Joined
- Jul 7, 2022
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
I have a table that monitors due dates, with several different due dates on each row.
On opening the workbook, I've got some VBA code that scans a range of cells to see if an item is within 7 days of "due", and opens a pop up box listing the name of those items.
When the current date is within 7 days of any of the due dates on that row, I use the following code to list the item names in the popup box using an offset to return results from a specific column where the item names are listed.
Problem is that it displays all resulting item names on one line in the pop up box, and I would like to make it display each result on a new line. How would I do that?
Currently my pop up box looks like:
"The following items are about to become due:"
"Item 1, Item 2, Item 3, Item 4," etc
Whereas I would like it to read:
"The following items are about to become due:"
"Item 1,
Item 2,
Item 3,
Item 4,"
etc As I think it would look tidier like this
This is the full code I am using at the moment:
Cheers
On opening the workbook, I've got some VBA code that scans a range of cells to see if an item is within 7 days of "due", and opens a pop up box listing the name of those items.
When the current date is within 7 days of any of the due dates on that row, I use the following code to list the item names in the popup box using an offset to return results from a specific column where the item names are listed.
Code:
If Date >= DateDue - Range("B2") Then
'Change the offset value to pick up the Item Name column in your data
NotificationMsg = NotificationMsg & " " & DateDue.Offset(0, -DateDue.Column + 1)
Problem is that it displays all resulting item names on one line in the pop up box, and I would like to make it display each result on a new line. How would I do that?
Currently my pop up box looks like:
"The following items are about to become due:"
"Item 1, Item 2, Item 3, Item 4," etc
Whereas I would like it to read:
"The following items are about to become due:"
"Item 1,
Item 2,
Item 3,
Item 4,"
etc As I think it would look tidier like this
This is the full code I am using at the moment:
VBA Code:
Option Explicit
Private Sub Workbook_Open()
'makes the code run every time the workbook is opened
Dim DateDueCol As Range
Dim DateDue As Range
Dim NotificationMsg As String
Set DateDueCol = Range("G8:G12, K8:K12, O8:O12, S8:S12 ") 'the range of cells that contain your due dates
For Each DateDue In DateDueCol
'B2 is the cell that tells the code to display popup box when due date is less than 7 days away.
If Date >= DateDue - Range("B2") Then
'Change the offset value to pick up the Item Name column in your data
NotificationMsg = NotificationMsg & " " & DateDue.Offset(0, -DateDue.Column + 1) 'This ensures that no matter which column the relevant due date is in, only results from the first cell in that row are displayed in the pop up box.
End If
Next DateDue
If NotificationMsg = "" Then
MsgBox "No items are due."
Else: MsgBox "The following are about to become due: " & vbNewLine & vbNewLine & NotificationMsg
End If
End Sub
Cheers