application.match failing when it shouldn't

Luke777

Board Regular
Joined
Aug 10, 2020
Messages
246
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I'm using the following piece of code to find a match

VBA Code:
rotaRow = Application.Match(acSTime, rotaTime, 0)

When the locals window shows the below (and other examples) it works perfectly.

: acSTime : 44725.2708333333 : Double
: rotaTime(1,1) : 44725.2708333333 : Variant/Double

but when I get to the following, it fails to find a match.

: acSTime : 44725.3333333333 : Double
: rotaTime(7,1) : 44725.3333333333 : Variant/Double

it runs fine for the first 17 times but fails on the above for some reason.

Full code code looks like the below
VBA Code:
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim acName As String
    Dim acSTime As Double, acFTime As Double
    Dim acSlots As Integer
    Dim eNumber As Long
    
    Set ws1 = Worksheets(1)
    Set ws2 = Worksheets(4)
    
    rotaENs = ws1.Range("C1", ws1.Range("C1").End(xlToRight))
    rotaTime = ws1.Range("A4", ws1.Range("A4").End(xlDown))
    
    For Each en In ws2.Range("A1", ws2.Range("A1").End(xlDown))
        eNumber = en.Offset(, 0)
        acName = en.Offset(, 12)
        acSTime = en.Offset(, 10)
        acFTime = en.Offset(, 11)
        acSlots = (acFTime - acSTime) * 96
        
        rCol = Application.Match(eNumber, rotaENs, 0)
        rRow = Application.Match(acSTime, rotaTime, 0)
        
    Next

Any ideas?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You can use the ROUND function to fix it:

eNumber = ROUND(en.Offset(, 0).Value, 10)

acName = ROUND(en.Offset(, 12).Value, 10)

...
 
Upvote 0
You can use the ROUND function to fix it:

eNumber = ROUND(en.Offset(, 0).Value, 10)

acName = ROUND(en.Offset(, 12).Value, 10)

...
any idea what place I need to round it to? I'm dealing with dates and times down to 15 minute intervals - so 11/06/2022 01:00:00 followed by 11/06/2022 01:15:00 doesn't need to be more granular than that
 
Upvote 0
strangely changing

VBA Code:
        rRow = Application.Match(acSTime, rotaTime, 0)

to

VBA Code:
        rRow = Application.Match(acSTime, rotaTime, 1)

seems to fix the issue without breaking anything further along.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

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