0% found this document useful (0 votes)
5 views2 pages

Code for find replace

This document contains a VBA macro for Excel that performs a find and replace operation across all worksheets in a workbook. Users can input the word to find, the word to replace it with, and specify the range of rows to search. After executing, a message box confirms the completion of the operation.

Uploaded by

xohel46436
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Code for find replace

This document contains a VBA macro for Excel that performs a find and replace operation across all worksheets in a workbook. Users can input the word to find, the word to replace it with, and specify the range of rows to search. After executing, a message box confirms the completion of the operation.

Uploaded by

xohel46436
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Sub FindAndReplaceInWorkbook()

Dim ws As Worksheet

Dim findWord As String

Dim replaceWord As String

Dim startRow As Long

Dim endRow As Long

Dim rng As Range

Dim cell As Range

' Input the words for find and replace

findWord = InputBox("Enter the word to find:")

replaceWord = InputBox("Enter the word to replace with:")

' Input the specific range of rows

startRow = Application.InputBox("Enter the starting row number:", Type:=1)

endRow = Application.InputBox("Enter the ending row number:", Type:=1)

' Loop through each worksheet in the workbook

For Each ws In ThisWorkbook.Worksheets

' Define the range to search

Set rng = ws.Rows(startRow & ":" & endRow)

' Loop through each cell in the defined range

For Each cell In rng

' Change this line to match your criteria

If LCase(cell.Value) = LCase(findWord) Then

cell.Value = replaceWord

End If

Next cell
Next ws

MsgBox "Find and replace operation completed."

End Sub

You might also like