EXCEL VBA Combo box filter not working with numerical value but does with text value

jocotterellash

New Member
Joined
Aug 29, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Dear all,

My combox below called cmbyear works fine filtering data when using a text values but doesn't work with numerical values.
I would like to filter on year (the data is in column 14) on shstaff. My report data is called emprpt1.
The combo box (cmbyear) uses rowsource in a named range and works for text values and not numerical values. I think I've formatted all correctly.
Slightly baffled on this one, many thanks in advance.






Sub employeeReport()

'employee column
shstaffEmpID = 1
shstaffFirstName = 2
shstaffLastName = 3
shstaffcountry = 4
shstaffComplete = 5 'works fine here
shstaffdepartment = 6
shstaffZip = 7
shstaffRegion = 8
shstaffPhone = 9
shstaffEmail = 10
shstaffMF = 11
shstaffETH = 12
shstaffDOB = 13
shstaffyear = 14 ' this column has year (numerical value) and is a problem
shstaffreg_group = 15
shstaffgender = 16
shstaffDateofbirth = 17
shstaffstatus = 18







'report cols
rEmpID = 1
rName = 2
rPhone = 3
rEmail = 4
rStatus = 5
ryear = 6

'last row
emplr = shStaff.Cells(Rows.Count, 1).End(xlUp).row

'rpt lr
rptlr = emprpt1.Cells(Rows.Count, 1).End(xlUp).row
'clear
emprpt1.range("a2:g" & rptlr + 1).ClearContents

rptRow = 2 'starting row

'loop
For empRow = 2 To emplr


If Me.cmbyear <> Empty And shStaff.Cells(empRow, shstaffyear) <> Me.cmbyear Then
GoTo nextRow
End If

this below text value filter work fine


' If Me.cmbyear <> Empty And shStaff.Cells(empRow, shstaffcomplete) <> Me.cmbyear Then
' GoTo nextRow
' End If




emprpt1.Cells(rptRow, rEmpID) = shStaff.Cells(empRow, shstaffEmpID)
emprpt1.Cells(rptRow, rName) = shStaff.Cells(empRow, shstaffFirstName) '& " " & shStaff.Cells(empRow, shstaffLastName)
emprpt1.Cells(rptRow, rPhone) = shStaff.Cells(empRow, shstaffPhone)
emprpt1.Cells(rptRow, rEmail) = shStaff.Cells(empRow, shstaffEmail)
emprpt1.Cells(rptRow, rStatus) = shStaff.Cells(empRow, shstaffstatus)
emprpt1.Cells(rptRow, ryear) = shStaff.Cells(empRow, shstaffyear)
'increase row num
rptRow = rptRow + 1



nextRow:
Next empRow



End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,223,884
Messages
6,175,174
Members
452,615
Latest member
bogeys2birdies

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