Find and replace text

oxygn

New Member
Joined
May 24, 2010
Messages
25
I have two excel spreadsheets. The first one is Field ID and has all Field ID's associated with field names Field ID Field Name 1000 Field 1 1001 Field 2 1002 Field 3 1003 Field 4 1004 Field 5 The other spreadsheet is the Rules spreadsheet IF ‘Field 1’ <> BLANK THEN ‘Field 2’ = 0 IF ‘Field 3’ = 0 AND ‘Field 4’ = 1 THEN ‘Field 5’ = 9 Problem: I want to write a macro that: 1. Can read rules from column Basic Rule in the Rules worksheet. The rules have field names in single quotes as would appear in when typed in microsoft word. They are not plain quote like '. 2. Go to the field worksheet and look for text e.g. Field 1 and get corresponding field id 1000 3. Come back on the Rules sheet and replace the field name with field id. Here is how the output should look like Rule IF ^1000 <> BLANK THEN ^1001 = 0 IF ^1002 = 0 AND ^1003 = 1 THEN ^1004 = 9 I have tried writing a find and replace macro but that does not work. I guess what I am looking for is some kind of pattern matching. Since I am a new to excel VBA I am having trouble with it. Any help will be much appreciated.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Sorry the formatting in the previous post got mixed up. I am posting the problem again:

I have two excel spreadsheets.

The first one is Field ID and has all Field ID's associated with field names
<TABLE dir=ltr border=0 cellSpacing=0 cellPadding=2 width=353><TBODY><TR><TD bgColor=#333399 height=23 width="43%">
Field ID​
</TD><TD bgColor=#333399 height=23 width="57%">Field Name
</TD></TR><TR><TD height=23 width="43%">
1000​
</TD><TD height=23 width="57%">Field 1
</TD></TR><TR><TD height=23 width="43%">
1001​
</TD><TD height=23 width="57%">Field 2
</TD></TR><TR><TD height=23 width="43%">
1002​
</TD><TD height=23 width="57%">Field 3
</TD></TR><TR><TD height=23 width="43%">
1003​
</TD><TD height=23 width="57%">Field 4
</TD></TR><TR><TD height=23 width="43%">
1004​
</TD><TD height=23 width="57%">Field 5
</TD></TR><TR><TD height=23 width="43%">
1005​
</TD><TD height=23 width="57%">Field 6
</TD></TR></TBODY></TABLE>

The other spreadsheet is the Rules spreadsheet

<TABLE dir=ltr border=0 cellSpacing=0 cellPadding=2 width=379><TBODY><TR><TD bgColor=#333399 height=23 width="21%">
#​
</TD><TD bgColor=#333399 height=23 width="79%">
Rule​
</TD></TR><TR><TD height=93 width="21%">
1​
</TD><TD height=93 width="79%">IF ‘Field 1’ <> BLANK
THEN
‘Field 2’ = 0
</TD></TR><TR><TD height=93 width="21%">
2​
</TD><TD height=93 width="79%">IF ‘Field 3’ = 0 AND ‘Field 4’ = 1
THEN
‘Field 5’ = 9
</TD></TR></TBODY></TABLE>
 
Problem:
I want to write a macro that:
1. Can read rules from column Basic Rule in the Rules worksheet. The rules have field names in single quotes as would appear in when typed in microsoft word. They are not plain quote like '.
2. Go to the field worksheet and look for text e.g. Field 1 and get corresponding field id 1000
3. Come back on the Rules sheet and replace the field name with field id. Here is how the output should look like

<TABLE dir=ltr border=0 cellSpacing=0 cellPadding=2 width=313><TBODY><TR><TD bgColor=#333399 height=23>
Rule​
</TD></TR><TR><TD height=93>IF ^1000 <> BLANK
THEN
^1001 = 0
</TD></TR><TR><TD height=93>IF ^1002 = 0 AND ^1003 = 1
THEN
^1004 = 9
</TD></TR></TBODY></TABLE>
 
I have tried writing a find and replace macro but that does not work. I guess what I am looking for is some kind of pattern matching. Since I am a new to excel VBA I am having trouble with it. Any help will be much appreciated.
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,172
Members
449,071
Latest member
cdnMech

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