Need assistance with vba Find method that does not find a string does exist.

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
833
Office Version
  1. 365
Platform
  1. Windows
As always this has to be something basic that I am missing...Code below shows what I have. I am looking for a specific string in a worksheet. Below the code shows where the string is in the target file. What the heck am I doing wrong? Call to Find throws up an "Automation error".

VBA Code:
Sub AddNames(pwsToolsWorksheet As Worksheet)
    
'   parameter pwsToolsWorksheet is the worksheet into which names are added.
    
'   Cell containing the header Tool Description
    Dim rCellFound As Range
    
'   Cells containing Tool Descriptions.
    Dim rDataCells As Range
    
'   The row of the last entry in the Tool Descriptions data.
    Dim iLastCellRow As Long
    
'   The column of the last header in the Tool Descriptions data.
    Dim iLastColumn As Long
            
'   Look for the text Tool Description in the worksheet
    'On Error Resume Next
    Set rCellFound = pwsToolsWorksheet.Cells.Find(What:="Tool Description", LookAt:=xlWhole)
    'On Error GoTo 0

The string sought is in cell A1!

Other3.xlsm
AB
1Tool DescriptionTool Part Number
2.002R PH HORN Bore BarR105.1813.005.0.25 TH35
3.008R Boring Bar InsertR105.1833.3.6 TH35
Tooling
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try:
VBA Code:
Sub AddNames()
    Dim rCellFound As Range, rDataCells As Range, iLastCellRow As Long, iLastColumn As Long
    Set rCellFound = Sheets("Tooling").Cells.Find(What:="Tool Description", LookAt:=xlWhole)
    MsgBox rCellFound
End Sub
 
Upvote 0
That was not quite the answer but it was helpful. Your post got me to take a second look and I was calling that sub in the wrong place in the caller sub such that the worksheet parameter was not being set before the call. Thanks very much!
 
Upvote 0
Solution
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,928
Members
449,094
Latest member
teemeren

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