Macro to find user inputted text in a worksheet

Cozkincaud

New Member
Joined
Apr 18, 2019
Messages
8
Hi

I need help with what should be a simple macro.

I need to search a column of book/article titles to find a book/article title that I paste into an Excel Find box.

I created a macro from some Internet posts, but get the error, “Run-time error ‘91’: Object variable or With block variable not set”.

This is the macro:

Sub CheckIfOneTabFilesDownloaded()
' Macro to check if Internet tabs sent to One Tab have already been downloaded
Dim Title As String
Sheets("Downloads - November 18, 2023").Select
ActiveSheet.Range("A1:A1").Select
Title = InputBox("Enter Title")
Dim fColumn As Range


Set Rng = Find(What:=Title, LookAt:=xlPart, LookIn:=xlValues, MatchCase:=False, After:=fColumn("A2"))

If fColumn Is Nothing Then
MsgBox "Nothing found"
Else:
fColumn.Activate
End If
End Sub


with the error line being the “Set Rng . . . “ statement.

My understanding is I am attempting to use an object variable that has yet to reference a valid object. The error is in the "Set Rng' statement. I assume the following lines are fine.

After an Internet search I added “Cells.Find” to my “Set Rng” statement but to no avail.

So I would be extremely grateful for whatever help and suggestions forum members can give.

My thanks in advance for whatever help and advice
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I need to search a column of book/article titles to find a book/article title that I paste into an Excel Find box.
I don't fully understand that part, but is there any reason why you don't just highlight column A and press Ctrl+F?
 
Upvote 0
Because, as you might see from my macro, I have to:

  1. Switch from one worksheet to another
  2. Go to the cell, A1
  3. Hit control F
I want to cut out these steps. I should probably add a statement returning me to the oriiginal worksheet if the title is not found

Thanks for your comment.
 
Upvote 0
See if this does what you wanted:
VBA Code:
Option Explicit
Sub FindTitle()
    Dim title As String, rng As Range
    title = InputBox("Enter Title")
    Set rng = Worksheets("Downloads - November 18, 2023").Range("A:A").Find(title, LookAt:=xlPart)
    
    If Not rng Is Nothing Then
        Application.Goto rng, scroll:=True
    Else
        MsgBox title & " could not be found"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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