Slab
Slab

Reputation: 363

.Find - putting variable in SearchDirection causes run-time error 13 - type mismatch

Why does this work:

Set rowNonBlankFound = Rows(rowToUse).Find(what:="*", after:=Cells(rowToUse, leftMostCol), LookIn:=xlValues, SearchDirection:=xlNext)

But this doesn't:

Dim direction As String direction = "xlNext" Set rowNonBlankFound = Rows(rowToUse).Find(what:="*", after:=Cells(rowToUse, leftMostCol), LookIn:=xlValues, SearchDirection:=direction)

I get run-time error 13 - type mismatch?

Upvotes: 0

Views: 27

Answers (2)

Nathan_Sav
Nathan_Sav

Reputation: 8531

Direction is an enumeration enter link description here needs to be a number or an enumeration equiv

Upvotes: 0

Vincent G
Vincent G

Reputation: 3188

SearchDirection is not a argument of type String, but of type XlSearchDirection, you cannot pass a string to it since there is no convertion from one to the other. xlNext is not identical to "xlNext"

Use following code:

Dim direction As XlSearchDirection
direction = xlNext
Set rowNonBlankFound = Rows(rowToUse).Find(what:="*", after:=Cells(rowToUse, leftMostCol), LookIn:=xlValues, SearchDirection:=direction)

Upvotes: 1

Related Questions