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

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
855
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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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

Forum statistics

Threads
1,224,586
Messages
6,179,713
Members
452,939
Latest member
WCrawford

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