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.
 

oxygn

New Member
Joined
May 24, 2010
Messages
25
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.
 

Forum statistics

Threads
1,082,257
Messages
5,364,074
Members
400,778
Latest member
Canadian Sal

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top