标签云

微信群

扫码加入我们

WeChat QR Code

My question is concerning the runtime error 91 in VBA for excel. I've done some searching to no avail. My code is below. I have noted the section causing the error. Why is this happening, and how can i fix it and move on?Sub RemoveFooterRows(theFile)Dim found As RangeDim aggregateRow''Error is from section belowfound = isItRow = Workbooks(theFile).Worksheets(1).Columns(1).Find _("Summary", Range("A1"), xlValues, xlPart, xlByRows, xlNext, False, , False)''Error is from section aboveMsgBox ("val is " & found.Row)End Sub


Also worth adding a check If Not found Is nothing Then... in case the value wasn't found.

2019年04月20日09分54秒

Okay, that works, I didn't realize I had the double assignment. But, how do I get the row, when I add a .Row at the end I get the same error. How do I assign the row of found to a variable?

2019年04月20日09分54秒

Add .row to what?It's already in the MsgBox line and returns fine for me.

2019年04月19日09分54秒

Good call on the checking for nothing Tim.

2019年04月19日09分54秒

the Suggested if block is being skipped, implying the value wasn't found, but I know it is there in the first column. What has gone wrong?

2019年04月19日09分54秒

What is the difference between your check and 'If Not found Is Nothing Then'

2019年04月20日09分54秒

Using your code and commented out On Error Resume next, I get the same error. I used the find as I had written it. I know the value is in the column A, why is the error existing?

2019年04月20日09分54秒

On Error Resume Next is there because if .Find doesn't find anything then .Row generates an error.

2019年04月19日09分54秒

I'm not a big fan of using Error Handling when a simple range object could be tested for Not Nothing. Plus Find can error out for other reasons that an unfound match, ie starting the seach in an invalid location, looking in an invalid range etc. Better to pinpoint these issues than skip over them

1970年01月01日00分03秒

Code-only answers are discouraged. Please click on edit and add some words summarising how your code addresses the question, or perhaps explain how your answer differs from the previous answer/answers. Thanks

2019年04月19日09分54秒