We help IT Professionals succeed at work.
Get Started

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

Last Modified: 2016-02-12
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
    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)
        End if

Open in new window

Watch Question
Social distance - Wear a mask - Don't touch your face - Wash your hands for 20 seconds
Most Valuable Expert 2017
Distinguished Expert 2020
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE