ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ListBox Add Item based on criteria (https://www.excelbanter.com/excel-programming/324080-listbox-add-item-based-criteria.html)

James W.[_2_]

ListBox Add Item based on criteria
 
I have a list box that is populated by the code below. I am having trouble
just showing todays entries. Column G is a time stamp of the entries made
and I would like the listbox to just show today's and not all the entries in
the excel database.


If Workbooks(xlDatabaseName).Sheets(xlTable).Range("A 2") < "" Then
With Workbooks(xlDatabaseName).Sheets(xlTable)
Set Rng = .Range("A1", .Range("A1").End(xlDown))
Set co = cell.Offset
End With

For Each cell In Rng.Cells
With UserForm1.ListBox1
.AddItem cell.Value
.List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
.List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
.List(.ListCount - 1, 3) = cell.Offset(0, 3).Value
.List(.ListCount - 1, 4) = cell.Offset(0, 4).Value
.List(.ListCount - 1, 5) = cell.Offset(0, 5).Value
.List(.ListCount - 1, 6) = cell.Offset(0, 6).Value

If .ListCount 5 Then
.TopIndex = .ListCount - 5
End If
If CheckBox1.Value = True Then
.ListIndex = .ListCount - 1
End If
End With
Next cell
End If

Thanks in advance

Tom Ogilvy

ListBox Add Item based on criteria
 
If Workbooks(xlDatabaseName).Sheets(xlTable).Range("A 2") < "" Then
With Workbooks(xlDatabaseName).Sheets(xlTable)
Set Rng = .Range("A1", .Range("A1").End(xlDown))
Set co = cell.Offset
End With

For Each cell In Rng.Cells
With UserForm1.ListBox1
if clng(cell.offset(0,6).Value) = clng(date) then
.AddItem cell.Value
.List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
.List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
.List(.ListCount - 1, 3) = cell.Offset(0, 3).Value
.List(.ListCount - 1, 4) = cell.Offset(0, 4).Value
.List(.ListCount - 1, 5) = cell.Offset(0, 5).Value
.List(.ListCount - 1, 6) = cell.Offset(0, 6).Value

If .ListCount 5 Then
.TopIndex = .ListCount - 5
End If
If CheckBox1.Value = True Then
.ListIndex = .ListCount - 1
End If
End if
End With
Next cell
End If


--
Regards,
Tom Ogilvy

"James W." wrote in message
...
I have a list box that is populated by the code below. I am having

trouble
just showing todays entries. Column G is a time stamp of the entries made
and I would like the listbox to just show today's and not all the entries

in
the excel database.


If Workbooks(xlDatabaseName).Sheets(xlTable).Range("A 2") < "" Then
With Workbooks(xlDatabaseName).Sheets(xlTable)
Set Rng = .Range("A1", .Range("A1").End(xlDown))
Set co = cell.Offset
End With

For Each cell In Rng.Cells
With UserForm1.ListBox1
.AddItem cell.Value
.List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
.List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
.List(.ListCount - 1, 3) = cell.Offset(0, 3).Value
.List(.ListCount - 1, 4) = cell.Offset(0, 4).Value
.List(.ListCount - 1, 5) = cell.Offset(0, 5).Value
.List(.ListCount - 1, 6) = cell.Offset(0, 6).Value

If .ListCount 5 Then
.TopIndex = .ListCount - 5
End If
If CheckBox1.Value = True Then
.ListIndex = .ListCount - 1
End If
End With
Next cell
End If

Thanks in advance





All times are GMT +1. The time now is 12:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com