Reset the value to C in column C if specific text is found "ar"

hsolanki

Board Regular
Joined
Jan 16, 2020
Messages
204
Office Version
  1. 2010
Platform
  1. Windows
Good Morning everyone

i was wondering if anyone could assist me, someone has kindly written the below code however it doesn't change all the Capital S and lowercase s to C if and when "ar" is entered or found in column C.

VBA Code:
Private Sub Worksheet_Calculate()

Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet
Set ws = wb.Sheets("LogDetails")
Dim Cell As Range

If ws Is Nothing Then
    Exit Sub 'possible way of handing no worksheet was set
End If
If Sheets("LogDetails").Visible = xlSheetVisible Then
Sheets("LogDetails").Visible = xlSheetVeryHidden
Else
Sheets("LogDetails").Visible = xlSheetVisible
End If
  Sheets("LogDetails").Select

Range("C3:C10000").Select
Set Cell = Selection.Find(What:="AR", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)

If Cell Is Nothing Then
    MsgBox "Did not found AR"

Else
    Columns("C").Replace What:="S", _
                            Replacement:="C", _
                            LookAt:=xlPart, _
                            SearchOrder:=xlByRows, _
                            MatchCase:=False, _
                            SearchFormat:=False, _
                            ReplaceFormat:=False
    Columns("C").Replace What:="s", _
                            Replacement:="C", _
                            LookAt:=xlPart, _
                            SearchOrder:=xlByRows, _
                            MatchCase:=False, _
                            SearchFormat:=False, _
                            ReplaceFormat:=False
End If

End Sub
 

Attachments

  • Sample book.png
    Sample book.png
    69 KB · Views: 32
Does that mean col C has a formula or not?
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Is that code in the "LogDetails" code module, or some other module?
 
Upvote 0
In that case I see no reason why it wouldn't work & it works for me.
Are you sure that code is actually running?
 
Upvote 0
Hi Yes the code runs however nothing happens as all the S remains the same it does not changes to C when AR is found
 
Upvote 0
How do you know that the code runs, if nothing changes?
 
Upvote 0
i tried doing an debug the code and had a msgbox if AR is found. also when code is finishes the S does not change to C on the sheet
 
Upvote 0
is there any alternative way to achieve the same result. when ar is found on column C all the capital S and lower S changes to C??
 
Upvote 0
Your code works for me as long as it's in the "LogDetails" code module, but will only run when a formula on that sheet is calculated.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,215
Members
453,024
Latest member
Wingit77

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