macro for replacing particular text

rd123

New Member
Joined
Dec 15, 2016
Messages
10
hi,

I am new to vba.

i want to find a particular text say it is "HI" and replace with some other which is in the one column in excel.say it is in column A.

actually i am trying to write a macro for sending a reply mail where it includes original text as well including to,from,sent,etc..

so i want to replace few of them. can anyone please help on this code.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

rd123

New Member
Joined
Dec 15, 2016
Messages
10
hi,

I am new to vba.

i want to find a particular text say it is "HI" and replace with some other which is in the one column in excel.say it is in column A.

actually i am trying to write a macro for sending a reply mail where it includes original text as well including to,from,sent,etc..

so i want to replace few of them. can anyone please help on this code.

i want to replace with the current activecell row.

.Text = " HI "
.replacement = Replace(.replacement, "HI", Cells(Application.ActiveCell.Row, 9))
 
Upvote 0

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
is "HI" the only text in the cell? or is there other text?

if it is the only text

Code:
Dim addr as string,addr2 as STring
addr = "A2:A" & range("A" & rows.count).End(xlup).row
addr2 ="I2:I" & range("I" & rows.count).End(xlup).row
Range(addr).Value = Evaluate("IF(" & addr & "=""HI""," & addr2 & "," & addr & ")")

this is if HI is in col A and the replacement text is in col I
 
Upvote 0

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
is "HI" the only text in the cell? or is there other text?

if it is the only text

Code:
Dim addr as string,addr2 as STring
addr = "A2:A" & range("A" & rows.count).End(xlup).row
addr2 ="I2:I" & range("I" & rows.count).End(xlup).row
Range(addr).Value = Evaluate("IF(" & addr & "=""HI""," & addr2 & "," & addr & ")")

this is if HI is in col A and the replacement text is in col I

and it excludes headers if you have them. If not change A2 and I2 to A1 and I1
 
Upvote 0

Forum statistics

Threads
1,191,204
Messages
5,985,270
Members
439,953
Latest member
suchitha

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