macro search text and add string next column

February 3, 2011 at 01:57:40
Specs: Windows 7
Hi, i really need help in macros urgently...
thanks in advance..

i have complete data of strings only in column 2.

Now i want to search throughout the sheet eg. search "amit" and i want to add a string "rathore"
in same row but in column 3.

thankyou please help... i am new to macros.

thanks


See More: macro search text and add string next column

Report •


#1
February 3, 2011 at 04:43:19
Sub AddString()
 For rw = 1 To Range("B" & Rows.Count).End(xlUp).Row
  If Range("B" & rw) = "amit" Then Range("C" & rw) = "rathore"
 Next
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#2
February 3, 2011 at 05:56:53
thanks for such a quick reply,,

but wht if i want to add it next column as well i.e column 4 instead of column 3.

and also if a cell string contains "amit" like "amit pratap" then also i have add "rathore" in cloumn 4.
because it is comparing only the cells which have only string "amit", i want if any part of string has "amit".

thanks again for ur reply i just wanted to know more so that it can clear my doubts.

thanks


Report •

#3
February 3, 2011 at 10:09:39
re: "amit pratap"


Sub AddString()
 For rw = 1 To Range("B" & Rows.Count).End(xlUp).Row
  If Range("B" & rw) Like "*amit*" Then Range("C" & rw) = "rathore"
 Next
End Sub

re: "but wht if i want to add it next column as well i.e column 4 instead of column 3."

You asked for Column 3. Are you now changing what you asked for?

What letter is associated with Column 2? What column letter is associated with Column 3? What column letter is associated with Column 4?

Look at the code. Try and see if you can modify the code to work with Column 4 instead of 3.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

Related Solutions


Ask Question