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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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,219,162
Messages
6,146,661
Members
450,706
Latest member
LGVBPP

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