Run Time Error 91, Cannot figure out what I am doing wrong?!

jmor22

New Member
Joined
Feb 10, 2022
Messages
1
Office Version
  1. 365
Platform
  1. MacOS
So I am trying to create a spreadsheet that if a cell in the first sheet matches a cell in the second sheet, that it sends a value from the first sheet to another cell in the second. Here is what I have written and I have gone over it a hundred and I definitely missing something. I have been doing VBA for maybe a week so I am extremely new.

Sub findsomething()
Dim rng As Range
Dim refno As String
Dim rownumber As Long

refno = Sheet3.Cells(8, 6)

Set rng = Sheet2.Columns("A:A").Find(What:=refno, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)

rownumber = rng.Row

Sheet1.Cells(rownumber, 8).Value = Sheet3.Cells(29, 5).Value

End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Runtime error 91 normally means the Find hasn't found the search item i.e. refno
 
Upvote 0
When stepping through your code I get no value returned from references like
?Sheet3.Cells(29,5).Value
in the immediate window. However, I do get valid returns using
?Sheets("Sheet3").Cells(29, 5).Value
which is what I thought the correct syntax should be. Surprises me that it doesn't raise an error, but then I'm coming from Access vba, which seems to be less tolerant of improper syntax used in object hierarchies.
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

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