VBA Find–Runtime Error 91

diminutivetasker

New Member
Joined
Jun 5, 2012
Messages
11
Hi All,

So I'm new to VBA. I received an error: Runtime Error 91 and I'm not sure how to fix it. I'm trying to cut and paste cells into another worksheet. Any help is much appreciated, thanks.


When I go into the debugger it highlights the following line of code as incorrect
:


Selection.Find(what:="TRUE", After:=ActiveCell, LookIn:=xlFormulas, _
Lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate



Full code below:


Sub Macro3()
'
' Macro3 Macro
'

'
Columns("M:M").Select
Selection.Find(what:="FALSE", After:=ActiveCell, LookIn:=xlFormulas, _
Lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Columns("A:A").EntireColumn.Select
ActiveCell.Offset(0, 1).Range("A1").Activate
Selection.Find(what:="TRUE", After:=ActiveCell, LookIn:=xlFormulas, _
Lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(-12, -13).Range("A1:N13").Select
ActiveCell.Activate
Selection.Cut
Application.CutCopyMode = False
Selection.Cut
Sheets("Sheet2").Select
ActiveSheet.Paste
Selection.End(xlDown).Select
ActiveCell.Offset(2, 0).Range("A1").Select
Sheets("Sheet1").Select

End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
The error is most likely happening because the Find is failing, ie not finding 'FALSE'.

When Find fails it returns nothing and you can't say Nothing.Activate.

Here's code that will prevent the error.
Code:
Dim rngFnd As Range

     Set rngFnd = Columns("M:M").Find(what:="FALSE", After:=ActiveCell, LookIn:=xlFormulas, _
        Lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)

     If rngFnd Is Nothing Then
          Msgbox "Not Found"
          Exit Sub
     End If

     rngFnd.Activate

     ' rest of code
 
Upvote 0

Forum statistics

Threads
1,211,434
Messages
6,101,838
Members
447,758
Latest member
jojo3strada

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