Replace data with other data in Excel

  • Thread starter Thread starter viriiman
  • Start date Start date
V

viriiman

In excel, I'm trying to replace a numeric value with another value
only in certain cells. For example, in cells C11 to C30, if I type in
the number one, I want that to be replaced with the number 28149. If I
type in the number two, I want that to be replaced with the number
28150 (etc). I don't want to use the replace option in excel
(Find...Replace), I would like to have this done automatically.

Please let me know what I need to do, and please go slow. I'm new to
all this.

Thanks.

Viriiman
 
Right click on the sheet tab for the worksheet where you want this to
happen.

Copy and paste the following code into the module

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C11:C30")) _
Is Nothing Then Exit Sub
If Target.HasFormula = True Then Exit Sub
If Not IsNumeric(Target.Value) Then Exit Sub
If Target.Value = 0 Then Exit Sub
Application.EnableEvents = False
Target.Value = Target.Value + 28148
Application.EnableEvents = True
End Sub

I've tried to cater for the obvious (to me) pitfalls but this may not cope
with everything you throw at it. Give it a try.

Regards

Trevor
 
Back
Top