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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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"
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,042
Members
448,940
Latest member
mdusw

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