macro find and replace cells

qkatfaw

New Member
Joined
Aug 29, 2011
Messages
3
I am having trouble with the creating a macro for the following.

I need to replace the text with a standard text.

The text I need to replace:
Complexity =2 XML script changes this was matched with the source
Complexity = 4 Site specific targeting
Complexity = 1 Site specific targeting changes this was matched
Complexity = 3 source files globally

What the text should be;
Standard 1
Simple 2
Medium 3
Complex 4

It is based on the number so complexity 1 with standard, complexity 2 with Simple etc .
Example:

Complexity = 4 Site specific targeting this will be replaced with (Complex)
Complexity = 3 source files globally this will be replaced with (Medium)

All text to be overwritten just the words Medium or Simple etc to remain.

If you could help that would be great thanks,Kate
<!-- / message -->
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
so.... just to be clear if the cell contains the number 1 after the = then put "Standard" ?

Do you want to keep the "Complexity = " as well or not?
 
Upvote 0
Hi ,

yes correct to your response.

"if the cell contains the number 1 after the = then put "Standard"


and No I don't want to keep the complexity.

Thanks
 
Upvote 0
hi kate,

maybe something like this will work for you.

it supposes that your listed items are all in columnA
Code:
Sub testthis()
Dim a() As Variant, x As Variant
Dim i As Long, j As Long, lr As Long
ReDim a(1 To 4, 1 To 2)

a(1, 1) = "Standard": a(1, 2) = 1
a(2, 1) = "Simple": a(2, 2) = 2
a(3, 1) = "Medium": a(3, 2) = 3
a(4, 1) = "Complex": a(4, 2) = 4

lr = Range("A" & Rows.Count).End(xlUp).Row

For i = 1 To lr
    If InStr(Cells(i, 1), "=") > 0 Then
        x = Split(Cells(i, 1), "=")(1)
        x = Split(Trim(x))(0)
    For j = 1 To 4
        If x * 1 = a(j, 2) Then Cells(i, 1) = a(j, 1): Exit For
    Next j
    End If
Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,919
Members
452,949
Latest member
beartooth91

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
Back
Top