pop up message all of data contain date when open file

Mussa

Active Member
Joined
Jul 12, 2021
Messages
264
Office Version
  1. 2019
  2. 2010
hi
I search for macro when open file . it pop up message show all of data based on col M contains date
so in my case it should show the rows 2,6,10

REP1.xlsm
ABCDEFGHIJKLM
1ITEMBATCH NOCODE NONAMEAMOUNTNOTESDATE
21BT-00CD-00ALI1250RECORDED03/08/2021
32BT-01CD-01ALI2200NOT RECORDED
43BT-02CD-02ALI3300NOT RECORDED
54BT-03CD-03ALI4400NOT RECORDED
65BT-04CD-04ALI5500RECORDED05/08/2021
76BT-05CD-05ALI6120NOT RECORDED
87BT-06CD-06ALI7300NOT RECORDED
98BT-07CD-07ALI8120NOT RECORDED
109BT-08CD-08ALI950RECORDED07/08/2021
1110BT-09CD-09ALI10120NOT RECORDED
1

the messgae should be like this
ITEMBATCH NOCODE NONAMEAMOUNTNOTESDATE
1BT-00CD-00ALI1250RECORDED
03/08/2021​
2BT-04CD-04ALI5500RECORDED
05/08/2021​
3BT-08CD-08ALI950RECORDED
07/08/2021​
 
this assumes that there is nothing in columns G-L that you want in the pop-up

1628460861731.png
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
You will need to create a Userform called UserForm1 and place a listbox called ListBox1 and a command button called CommandButton1 on the form so it looks like the below
1628479654115.png

The following settings should be changed
UserForm1
Height = 278.25
Width = 455.25

ListBox1
Height = 200
Width = 430

Once this is done, right click on the userform and select "View Code". Copy the code below into the UserForm1 vbe
1628479976269.png

VBA Code:
Private Sub CommandButton1_Click()
    Unload Me
End Sub

Private Sub UserForm_Initialize()
    Load UserForm1
    With ListBox1
        .ColumnCount = 13
        .ColumnWidths = "1 cm;2 cm;2 cm;2 cm;2 cm;3 cm;0;0;0;0;0;0;3 cm"
        .List = ShowDateData()
        .ListIndex = 0
    End With
    With UserForm1
        .StartUpPosition = 0
        .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
        .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
    End With
End Sub

Private Function ShowDateData() As Variant
    Dim arr() As Variant
    Dim arr2() As Variant
    Dim lRow As Long, i As Long, j As Long, k As Long, arr2Rows As Long
    Dim ws As Worksheet
    
    Set ws = ActiveSheet
    k = 0
    
    With ws
        lRow = .Cells(.Rows.Count, "M").End(xlUp).Row
        arr2Rows = WorksheetFunction.CountA(.Range("M:M"))
        arr = .Range("A1:M" & lRow)
        ReDim arr2(arr2Rows - 1, UBound(arr, 2) - 1)
        For i = 1 To UBound(arr, 1)
            If arr(i, UBound(arr, 2)) <> "" Then
                For j = 0 To UBound(arr, 2) - 1
                    arr2(k, j) = arr(i, j + 1)
                Next
                k = k + 1
            End If
        Next i
    End With
        
    ShowDateData = arr2
End Function

To run this code when the workbook is open place this code in the Workbook Open section of the "ThisWorkbook" vbe
1628480024778.png

VBA Code:
Private Sub Workbook_Open()
    UserForm1.Show
End Sub
 
Upvote 0
it gives error subscript out of range in this line
Code:
UserForm1.Show
VBA Code:
Private Sub Workbook_Open()
UserForm1.Show
End Sub
 
Upvote 0
Please create a test macro by placing this code in the vbe

VBA Code:
Sub Test()
UserForm1.Show
End Sub

then debug and step through the code until you get the error and let me know the code that it stops on.
 
Upvote 0
You will have to show the "debup" toolbar in the vbe and click the "Step Into" icon see picture below. Continue clicking the icon to step through each line of the code until the error appears.

1628519643976.png
 
Upvote 0
In the VB Editor goto Tolls, Options, General & then check the box next to "Break in class module" that way you should get to see what is causing the error.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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