1

I get "Application-Defined or Object-Defined Error" while I run the below Macro.

I want to parse through each column in "DB" sheets and search for that column.

Sub test()  
Dim FindString As Range
Dim Rng As Range

Dim i, j As Integer
Dim finalcol As Long

Worksheets("DB").Select

finalcol = Worksheets("DB").Cells(1, Application.Columns.Count).End(x1toleft).column
On Error Resume Next

For i = 1 To finalcol
    FindString = Cells(1, i).Value

    If Trim(FindString) <> "" Then
        With Sheets("DB").Range("A:A")
            Set Rng = .Find(What:=FindString, _
                        After:=.Cells(.Cells.Count), _
                        LookIn:=xlValues, _
                        LookAt:=xlWhole, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, _
                        MatchCase:=False)
            If Not Rng Is Nothing Then
                Application.Goto Rng, True
            Else
                MsgBox "Nothing found"
            End If
        End With
    End If
Next i
On Error GoTo 0

End Sub

1 Answer 1

4

Your x1toleft constant should be xlToLeft (ex ell, not ex one). The fact that it doesn't convert to camel case is a tip-off.

Also, FindString should be Dim FindString As String not as Range. If you get rid of the On Error Resume Next line, you'll get an error on FindString = Cells(1,i).Value line because you have to use Set with object variables. When it runs and the error is suppressed, FindString (as a Range variable) is Nothing.

I didn't get the error you got, it just couldn't find anything. But if you make those changes, it will either fix it or expose the real error. In any case, you should remove error handling until you have it debugged, then add it back.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.