We help IT Professionals succeed at work.

Object Required error, on FoundCell = RangeToSearch.find(string)

Having an odd issue, probably something very simple I'm overlooking. I've used the code below on dozens of other macros without issue, but for some reason this time I'm getting a 1004 error, Object Required on the line

Set FoundCell = RangeToSearch.Find(What:=sWhat, LookIn:=xlValues, LookAt:=xlPart).Activate

Open in new window

in the below code, any suggestions on what could be causing this would be greatly appreciated.


Dim wb As Workbook 
Dim sDir As String, sProj As String, sColBillable As String, sColProj As String, sColWBS As String
Dim ArrBillable() As String, sWhat As String
Dim i As Integer, iRow As Integer
Dim RangeToSearch As Range
Dim FoundCell As Range
Dim lCol As Long

sWhat = "Billing"

Set wb = Workbooks.Open("\\xxxxx\xxxxx\_xxxxx\file.xlsm", False, True)

With wb
    Rows("5:5").Select
    Set RangeToSearch = Selection
    Set FoundCell = RangeToSearch.Find(What:=sWhat, LookIn:=xlValues, LookAt:=xlPart).Activate
        If Not FoundCell Is Nothing Then
            lCol = RangeToSearch.Find("Billing").Column
            sColBillable = ColumnName(lCol)
        else
        End if

Open in new window

Comment
Watch Question

"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Remove the .Activate

Author

Commented:
Thank you.
Martin Liss"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014