Search Text file for cell value then replace regex match in text file from cell value 7 columns over from first match

meirbabboon

New Member
Joined
May 5, 2015
Messages
7
I am attempting to use a macro to open a text file and search for a match in column d then when the match is found look back in the text file for the MAC address and replace it with the cell value 7 columns over from first match. I will post examples of what I am trying to do.

Step 1. look at active sheet range D3:D13
Step 2. find hostname (range D3:D13 of excel file) in text file
[TABLE="width: 500"]
<tbody>[TR]
[TD]Column D - Hostnames[/TD]
[TD]Column K - MAC Addresses[/TD]
[/TR]
[TR]
[TD]ST999WAP200[/TD]
[TD]74-E0-A9-0B-68-31[/TD]
[/TR]
[TR]
[TD]ST999WAP201[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]ST999WAP100[/TD]
[TD]DC-72-E5-E5-09-0C[/TD]
[/TR]
[TR]
[TD]ST999WAP101[/TD]
[TD]A2-E9-87-03-3F-9E[/TD]
[/TR]
[TR]
[TD]ST999WAP102[/TD]
[TD]69-E1-76-FC-B7-4E[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Step 3. Replace the generic MAC (AA-BB-CC-DD-EE-FF) in text file with the matching row (column 7) from hostname search

ap6522 AA-BB-CC-DD-EE-FF
use profile ap6522
use rf-domain st999
hostname st999wap200
ip default-gateway 1.1.1.1
interface vlan1
ip address 1.1.1.2/22


ap6522 AA-BB-CC-DD-EE-FF
use profile ap6522
use rf-domain st999
hostname st999wap100
ip default-gateway 1.1.1.1
interface vlan1
ip address 1.1.1.3/22

ap6522 AA-BB-CC-DD-EE-FF
use profile ap6522
use rf-domain st999
hostname st999wap101
ip default-gateway 1.1.1.1
interface vlan1
ip address 1.1.1.4/22

ap6522 AA-BB-CC-DD-EE-FF
use profile ap6522
use rf-domain st999
hostname st999wap102
ip default-gateway 1.1.1.1
interface vlan1
ip address 1.1.1.5/22

Step 4. Save Text file with replacements

Any assistance would be greatly appreciated. If this could be a button that I can add to the sheet that would be great.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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