Replacing part of a cell text

O

oOpsy

Hi there!

I'm working on a macro to automate my project, One thing i need to do
now is to replace the numerals in a cell from another cell. For
example, in sheet1 C2, i have this numeral 20. I will like this macro
to replace sheet3 C2 which contains data such as 11. I want the numeral
11 to be replaced by 20. Hope someone can help with this!

Another thing is how do i call from excel macro to ask notepad to open
up a .xml file?

Thanks a lot!
 
G

Gary Keramidas

not knowing how much you have to do, this will solve your example

Worksheets("sheet3").Range("c2").Value = Worksheets("Sheet1").Range("c2")
 
O

oOpsy

Hi Gary!

Thanks for the code. But sorry that i left out something impt! In
sheet3, C2, i have data such as <val>11</val>. I want to replace just
the numeral 11 from the numeral 20 which i copy from Sheet 1 C2. Is
that possible? So that in the end, sheet3 C2 will display as
<val>20</val>

Thanks!
 
G

Gary Keramidas

try this

Sub test2()
Worksheets("sheet3").Range("c2").Value = _
Replace(Worksheets("sheet3").Range("c2"), "11", _
Worksheets("sheet1").Range("c2").Value)
End Sub
 
G

Gary Keramidas

or, if the 11 can be any 2 digit number:

Sub test3()
Worksheets("sheet3").Range("c2").Value = _
Replace(Worksheets("sheet3").Range("c2"), _
Mid(Worksheets("sheet3").Range("c2"), 6, 2), _
Worksheets("sheet1").Range("c2").Value)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top