• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Find and Replace

skelly90

New Member
I have the below script for finding and replacing values on my sheet, but it changes all cases. I only want it to change if the value is in column "D"?

Please can somebody advise.


Many thanks


Option Explicit


Sub ChgInfo()


Dim WS As Worksheet

Dim Search As String

Dim Replacement As String

Dim Prompt As String

Dim Title As String

Dim MatchCase As Boolean


Prompt = "What is the original value you want to replace?"

Title = "Search Value Input"

Search = InputBox(Prompt, Title)


Prompt = "What is the replacement value?"

Title = "Search Value Input"

Replacement = InputBox(Prompt, Title)


For Each WS In Worksheets

WS.Cells.Replace What:=Search, Replacement:=Replacement, _

LookAt:=xlPart, MatchCase:=False

Next


End Sub
 
Change ws.cells to ws.range("D:D")


in the line

WS.Cells.Replace What:=Search, Replacement:=Replacement, _
 
Try this:

[pre]
Code:
Sub ChgInfo()
Dim WS As Worksheet
Dim Search As String
Dim Replacement As String
Dim Prompt As String
Dim Title As String
Dim MatchCase As Boolean

Prompt = "What is the original value you want to replace?"
Title = "Search Value Input"
Search = InputBox(Prompt, Title)

Prompt = "What is the replacement value?"
Title = "Search Value Input"
Replacement = InputBox(Prompt, Title)

For Each WS In ThisWorkbook.Worksheets
WS.Columns("D:D").Replace What:=Search, Replacement:=Replacement, _
LookAt:=xlPart, MatchCase:=False
Next WS

End Sub
[/pre]
 
Back
Top