If function coded incorrectly ..by me

60john

Board Regular
Joined
Apr 25, 2013
Messages
80
Can someone tell me what is wrong with this please?

Cells.Select
If Selection.Find(What:="Ship 1", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate Is True Then
ActiveCell.Select
ActiveCell.FormulaR1C1 = "Lady Luck"
End If
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

nuked

Well-known Member
Joined
Mar 20, 2013
Messages
883
Pretty much everything.

What are you trying to achieve.
 

60john

Board Regular
Joined
Apr 25, 2013
Messages
80
Pretty much everything.

What are you trying to achieve.

It's just a small piece of code in a larger macro.

I am trying to search an entire workbook for a cell containing the text "Ship 1". If it is found I want the text in the cell to be changed to "Lady Luck"
 

nuked

Well-known Member
Joined
Mar 20, 2013
Messages
883
There's probably a better way, but this should do:

Code:
Option Explicit
Sub ReplaceShipWithLadyLuck()
Dim rng As Range
Dim wks As Worksheet
For Each wks In Worksheets
Set rng = wks.Cells.Find("Ship1")
If Not rng Is Nothing Then
    rng = "Lady Luck"
    Exit Sub
    
End If
Next wks

End Sub
 

60john

Board Regular
Joined
Apr 25, 2013
Messages
80
There's probably a better way, but this should do:

Code:
Option Explicit
Sub ReplaceShipWithLadyLuck()
Dim rng As Range
Dim wks As Worksheet
For Each wks In Worksheets
Set rng = wks.Cells.Find("Ship1")
If Not rng Is Nothing Then
    rng = "Lady Luck"
    Exit Sub
    
End If
Next wks

End Sub

Thanks nuked. That did the trick.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,140
Messages
5,599,964
Members
414,352
Latest member
macquarie_jchan58

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
Top