Question

I'm using the WorksheetFunction.Match in a temporary workbook.

Dimen = WorksheetFunction.Match(sum.Range("A15"), temp.Sheets(1).Range("A1:A200"))
colNum = WorksheetFunction.Match(sum.Range("A15"), temp.Sheets(1).Range("32:32"))

Dimen1 = WorksheetFunction.Match(sum.Range("A16"), temp.Sheets(1).Range("A1:A200"))
colNum1 = WorksheetFunction.Match(sum.Range("A16"), temp.Sheets(1).Range("33:33"))

Dimen2 = WorksheetFunction.Match(sum.Range("A17"), temp.Sheets(1).Range("A1:A200"))
colNum2 = WorksheetFunction.Match(sum.Range("A17"), temp.Sheets(1).Range("34:34"))

Dimen3 = WorksheetFunction.Match(sum.Range("A18"), temp.Sheets(1).Range("A1:A200"))
 colNum3 = WorksheetFunction.Match(sum.Range("A18"), temp.Sheets(1).Range("35:35"))

Dimen4 = WorksheetFunction.Match(sum.Range("A19"), temp.Sheets(1).Range("A1:200"))
colNum4 = WorksheetFunction.Match(sum.Range("A19"), temp.Sheets(1).Range("36:36"))

The last two lines:

Dimen4 = WorksheetFunction.Match(sum.Range("A19"), temp.Sheets(1).Range("A1:200")) 
colNum4 = WorksheetFunction.Match(sum.Range("A19"), temp.Sheets(1).Range("36:36"))

it comes up with the 1004 error, I do not know the reason for that error and how to solve it?

Was it helpful?

Solution

Try

Dimen4 = WorksheetFunction.Match(sum.Range("A19"), temp.Sheets(1).Range("A1:A200")) 
colNum4 = WorksheetFunction.Match(sum.Range("A19"), temp.Sheets(1).Range("A36").EntireRow)

and probably change it in all lines. It would fail everywhere I guess..

The reasons are:

  • Range("A1:200") is invalid syntax

As DG pointed out in the comment below, Range("1:1").Address does work, it is not at all invalid!

OTHER TIPS

This is the error that occurs when the the Match function does not find a match. Since you're not supplying the third argument to Match, the problem could be that: a) the values in the range you're searching are not sorted in ascending order, and/or, b) the value you're searching for is less than all the values in the range you're searching.

Try this:

Dim Result As Variant
If Not VBA.IsError(Application.Match(...)) Then
    Result = Application.Match(...)
End If

This tries the match and if there is an error on the function it will not assign a result.

WorksheetFunction.Match Method (Excel)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top