VBA MATCH function issue

dancingcab

New Member
Joined
Nov 10, 2014
Messages
14
Hi,

I'm fairly new to VBA so please forgive my lack of knowledge!

I'm trying to use the Match function but get a run-time error 1004. My code is as follows:

Sub CAAnalysis()


Worksheets(1).Activate


Start1 = Application.WorksheetFunction.Match(0.05, "$A:$A", 1)


Debug.Print Start1


End Sub

I know that the value 0.05 exists in column A. However, the actual value is 0.0499999998737621. I noticed that the Match function says As Double when I click the quick info button. Is the issue that the value is more than 15 decimal places?

Thanks!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
This should work for you

Code:
Sub CAAnalysis()

Worksheets(1).Activate

Start1 = [MATCH(0.05,ROUND(A:A,10000),0)]
Debug.Print Start1

End Sub
 
Upvote 0
Hi,

If I use:

Start1 = [MATCH(0.05,ROUND(A:A,10000),0)]

I get a Type Mismatch error. I presume this is because I have defined start1 as an integer (which it should be as I'm hoping it will give me the the row number for that value). If I take out the [Dim Start1 As Integer] line I get an error 2042 (#N/A).

Full code:
Dim Start1

Sub CAAnalysis()


Worksheets(1).Activate


Start1 = [MATCH(0.05,ROUND(A:A,10000),0)]


Debug.Print Start1




End Sub
 
Upvote 0
Sorry this better

Code:
Sub CAAnalysis()
Dim Start1 as integer
 Worksheets(1).Activate

Start1 = [MATCH(0.05,ROUND(A:A,5),0)]

Debug.Print Start1

End Sub
 
Upvote 0
Thank you! This works :)

The square brackets are new to me - can you point me in the direction of any tutorials which help explain what this is doing?

Thanks!
 
Upvote 0

Forum statistics

Threads
1,216,050
Messages
6,128,498
Members
449,455
Latest member
jesski

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