Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Last Item of Listbox not getting displayed Raj Excel Discussion (Misc queries) 0 April 22nd 08 10:58 AM
Adding item in listbox volabos Excel Worksheet Functions 0 December 3rd 07 11:47 AM
Adding item in listbox volabos Excel Worksheet Functions 0 December 3rd 07 11:27 AM
Item order in ListBox [email protected] Excel Discussion (Misc queries) 1 June 16th 06 01:15 PM
The value of a ListBox Item TK Excel Programming 2 August 20th 04 06:17 AM


All times are GMT +1. The time now is 03:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"