Listbox not showing proper data

xsmurf

Board Regular
Joined
Feb 24, 2007
Messages
55
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'am hoping to get some help here.
I have a userform that needs to show values, if some criteria is met.
please see attached file. ( extra data has been removed )

How it should work:
I fill in the clocknumber and the job is being shown => this works
then I fill in the StartDate & EndDate.
Now when I press "commandbutton1" it should show me results in the listbox => this works too.

The Problem:
It shows info that is not supposed to be there.

It should only show information that is within the criteria.
For example:
If my clocknumber=1 ( job=Painter) and my StartDate= 01/01/2023 and EndDate= 01/13/2023, it should only list all the names that match the criteria and are falling on or in between the Start/EndDate.
In this case only employee 1 / 3/ 5 should be in the list, not all the painters.

Hope someone can assist me with this problem, any help is appreciated.

Also I would not like to see double names in the list if multiple dates are found. The name should be shown once, and then the dates would need to be horizontally next to that name ( now every date is a row) .
Don't know if this is possible.

Thanks again

example file
 
With the approach we used the listbox includes a single column, and the data looks aligned using the "Tab" that align the text at specific columns (and I don't know if the tab-stops can be set at a desired position).
The only option I could think about is setting the Listbox for the font=Courier new and maybe size= 8 points
Then we could use a calculated string to pad the lenght of the text to a predefined length.
I guess this affects the data in ws.Cells(row, 3).Value and ws.Cells(row, 4).Value (or row,4 and row,5 if you reallocated the data layout), whereas Format(currentDate, "dd/mm/yyyy") should give a string with fixed length and thus could be amended by a fixed lenght string

This also requires that you define which should be the width allocated for the first field (for example: 15) and for the second one (for example 20)
then replace the line rowData = ws.Cells(row, 3).Value & vbTab & ws.Cells(row, 4).Value with

VBA Code:
        rowData = Left(ws.Cells(row, 3).Value, 14) & String(15 - Len(ws.Cells(row, 3).Value), " ") & Left(ws.Cells(row, 4).Value, 14) & String(20 - Len(Left(ws.Cells(row, 4).Value, 19)), " ")

and the line rowData = rowData & vbTab & Format(currentDate, "dd/mm/yyyy") with
VBA Code:
rowData = rowData & Format(currentDate, "dd/mm/yyyy") & "  "
 
Upvote 1

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
@Anthony47
it was a little tricky to finetune
The horizontal bar might not be the best when it comes to size/length, but it works for what I want.

Thank you so much for your help.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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