How to populate this ListBox meeting a date criteria? This criteria comes from a selected cell

asantos2021

New Member
Joined
Nov 24, 2021
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I've been trying to put this one together, but no success so far.
VBA Code:
Option Explicit

Public Sub listBoxPopulate()
Dim data As Date
Dim BB As String
Dim CC As String
Dim DD As Date
Dim DateVal As Date

TBL = Worksheets("PartsData").Range("A1:C100")
DateVal = Selection.Value
UserForm1.ListBox1.Clear
Debug.Print DateVal

DD = 0

For BB = 1 To UBound(TBL, 1)
    If Val(DateVal.Value) = Val(TBL(DD, 3)) Then
        DD = DD + 1
        With frmParts.ListBox1
            .ColumnCount = 3
            .AddItem
            For CC = 1 To 3
               .Column(CC - 1, DD - 1) = TBL(BB, CC)
            Next CC
        End With
    End If
Next BB
MsgBox TBL
End Sub


Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PartsData")

'''find  first empty row in database
''iRow = ws.Cells(Rows.Count, 1) _
''  .End(xlUp).Offset(1, 0).Row
'revised code to avoid problems with Excel tables in newer versions
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

'check for a part number
If Trim(Me.txtTask.Value) = "" Then
  Me.txtTask.SetFocus
  MsgBox "Please enter a task."
  Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 3).Value = Me.txtDate.Value
ws.Cells(iRow, 2).Value = Me.txtTime.Value
ws.Cells(iRow, 1).Value = Me.txtTask.Value

'clear the data
Me.txtDate.Value = ""
Me.txtTime.Value = ""
Me.txtTask.Value = ""
Me.txtTask.SetFocus

End Sub

Private Sub cmdClose_Click()
  Unload Me
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, _
  CloseMode As Integer)
  If CloseMode = vbFormControlMenu Then
    Cancel = True
    MsgBox "Please use the button!"
  End If
End Sub

It shows the userForm with empty fields and it says there's insufficient memory error, as I close the userform.

Any help will be appreciated.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Part of my question above vanished, but the challenge is:
Get selected cell value, which is a date. Upon this selection, the userform pops up;
Filter the range A1:C10000, where col C contains the dates to be compared;
Populate the listBox, within the userform.

Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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