Syntax in a long FIND formula

zookeepertx

Well-known Member
Joined
May 27, 2011
Messages
576
Office Version
  1. 365
Platform
  1. Windows
Hello all!

I was recently given some VBA code and am trying to decipher it. One of the items is a FIND formula with a lot of commas at the end, which, I'm sure represent parameters for the FIND. But I can NOT figure them out! I've been googling forever and all I can come up with is that the beginning syntax is FIND(find_text, within_text, [start_num]) but nothing that tells me what the rest of the formula is doing. Can anyone help me? Here's the formula:
b = Columns(clm.Column).Find(Cells(d, clm.Column).Value, , , , , 1).Row
When the macro gets to that line it fails with the error message "Run-time error '91': Object variable or With block variable not set", which I don't know what that means, either.
* * * Please note that "clm.Column" just represents the column that the user selected earlier in the code. * * *

Thanks for any help

Jenny
 
Using Find like that results in an error if it cannot find the value. One way to avoid that is instead of structuring like this:
VBA Code:
b = Columns(clm.Column).Find(Cells(d, clm.Column).Value, , , , , 1).Row
do somethinig like this:
VBA Code:
Dim rngB as Range
Set rngB = Columns(clm.Column).Find(Cells(d, clm.Column).Value, , , , , 1)
If rngB is Nothing Then
    MsgBox "Value not found"
Else
    b = rngB.Row
End If
 
Upvote 0

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
I'll give that a try on Monday. Time to clock out if I don't want to get in trouble. ;)
 
Upvote 0
VBA Code:
Code:
Dim rngB as Range
Set rngB = Columns(clm.Column).Find(Cells(d, clm.Column).Value, , , , , 1)
If rngB is Nothing Then
    MsgBox "Value not found"
Else
    b = rngB.Row
End If

I just tried that and got "Value not found", even though I know there are more instances of the value being searched for. So, then I thought maybe both a and b needed to be coded like that and repeated it with reference to a. Still got the "Value not found" except it showed up twice in a row. (At least it was different, LOL!

I have to clock out in about 6 minutes to avoid trouble (we're not allowed to have even 1 minute over 40 hrs in a week), so I'll have to revisit this on Monday.

Thanks!

Jenny
 
Upvote 0

Forum statistics

Threads
1,215,756
Messages
6,126,692
Members
449,330
Latest member
ThatGuyCap

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