VBA: Outputting row number based on an exact MATCH case (i.e 0) not working?

Matonking

New Member
Joined
Jun 6, 2015
Messages
3
Hello,

VBA scripting query.

What I'm trying to do is find the ROW number for a specified time increment on a specific column (just a number) so that I can call this row number up later on. However, when I use the below script as part of my WorksheetFunction

Code:
Match(TIME, Range("I:I"), 0)

I continually get either N/A or no result even though I can quite clearly see the Time value in column I:I. In fact, even if I attempt to do the same above directly within the worksheet it will only seem to find the row number if the TIME value that I specify is within the first 5, or so, rows.

I kept thinking that it may be a floating point issue but I'm not using these numbers within an equation so they should no have an floating point error accumulations.

I have resorted to using the below script:

Code:
If Cells(15, 4) >= Cells(7, 4) Then                    
                    
                    Dim Time_Row As Integer
                    Dim Time_Row_Output As Integer
        
                    On Error Resume Next
                    Time_Row = Application.WorksheetFunction.Match(TIME, Range("I:I"), 1)
                    On Error GoTo 0
         
                            If Time_Row > 0 Then
            
        
                                    If Cells(Time_Row, 9) - TIME = 0 Then
            

                                        Time_Row_Output = Time_Row   

                                        Cells(28, 2) = "Equals 0"   ' THESE ARE JUST PROOF CHECKS THAT ARE DISPLAYED WITHIN THE WORKSHEET
                                        Cells(32, 2) = Time_Row_Output   
                                        Cells(33, 2) = Cells(Time_Row_Output, 9)  
            
                                    ElseIf Cells(Time_Row, 9) - TIME< 0 Then
            

                                        Time_Row_Output = Time_Row + 1

                                        Cells(28, 2) = "Less than 0"   ' THESE ARE JUST PROOF CHECKS THAT ARE DISPLAYED WITHIN THE WORKSHEET 
                                        Cells(32, 2) = Time_Row_Output   
                                        Cells(33, 2) = Cells(Time_Row_Output, 9)    
            
                                    ElseIf Cells(Time_Row, 9) - TIME > 0 Then
            
                                        Time_Row_Output = Time_Row - 1

                                        Cells(28, 2) = "Greater Than 0"   ' THESE ARE JUST PROOF CHECKS THAT ARE DISPLAYED WITHIN THE WORKSHEET 
                                        Cells(32, 2) = Time_Row_Output   
                                        Cells(33, 2) = Cells(Time_Row_Output, 9) 
                                    End If
                
                            Else
                
                                Time_Row_Output = 5   ' This is the row number that would occur if the initial starting time is above the specified time 
                
                            End If
                            
                                Cells(35, 2) = Time_Row_Output
                                Cells(36, 2) = Cells(Time_Row_Output, 9)
        
                    End If

In this code I am forced to use the MATCH(TIME,I:I,1) calling to even find any value (using -1 doesn't work either) but this has a seemingly random distribution of values as it can either be above, below or equal to the TIME value that I am trying to locate. So I had to include additional IF checks to say "IF less than TIME then add 1 row number" , "IF equal to TIME then don't add any row numbers" etc but this doesn't even work!! It will use use the "LESS THAN" function even though the output for the solution is, in some instances, the correct row number so it should have used the "EQUAL TO" Function.

It's driving me nuts trying to get this to work.

Can anyone help me?
 
Last edited:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,206,754
Messages
6,074,747
Members
446,082
Latest member
fgiron83

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