Find & Replace using VBA

Status
Not open for further replies.

Burrgogi

Active Member
Joined
Nov 3, 2005
Messages
495
Office Version
  1. 2010
Platform
  1. Windows
In col. B, I have the following:
apples1.txt
apples2.txt
chartsa.jpg
chartsb.jpg
objects.jpg
travelagenda.txt


In col. C, I would like the following:
_layer1.txt
_layer2.txt
_layer1.jpg
_layer2.jpg
_layer.jpg
_layer.txt


So, I recorded a very simple macro

Find: *1.txt
Replace with: _layer1.txt

Find: *1.jpg
Replace with: _layer1.jpg

Find: *2.txt
Replace with: _layer2.txt

Find: *2.jpg
Replace with: _layer2.jpg

For whatever reason, the macro does NOT work. It only works 1/2 the time.
_____________________________________________________________________

The 2nd part of my problem is that in that in col. B, I have:
3425816_7928501.jpg

In col. C, I want:
_layer.jpg

I don't know of any find & replace method that will achieve this.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Shoot, I can't edit my post, the time limit has expired.

=================== ***** REVISED POSTING ***** ===================
In col. B, I have the following:
apples1_hw.txt
apples2_hw.txt
chartsa_hw.jpg
chartsb_hw.jpg
chartsc_hw.jpg
cooler.jpg
toys.jpg
travelagenda_hw.txt


In col. C, I would like the following:
_layer1.txt
_layer2.txt
_layer1.jpg
_layer2.jpg
_layer.jpg
_layer.txt

Basically I want the macro to look at each element, does the element represent a series as in chartsa_hw; chartsb_hw; chartsc_hw...?(same example with "apples"). If so, then give me a output in col. C layer1, layer2, layer 3 etc....

So, I recorded a very simple macro

Find: *1_hw.txt
Replace with: _layer1.txt

Find: *1_hw.jpg
Replace with: _layer1.jpg

Find: *2_hw.txt
Replace with: _layer2.txt

Find: *2_hw.jpg
Replace with: _layer2.jpg

Problem is that if you look at travelagenda_hw.txt, the macro I recorded gives me an output of _layer1.jtxt because "travelagenda" ends with the letter 'a'.

And For whatever reason, the macro does NOT work if there is no such occurrence of examples like "travelagenda". Very odd. It only works 1/2 the time.
_________________________________________________________________

The 2nd part of my problem is that in that in col. B, I have:
3425816_7928501.jpg

In col. C, I want:
_layer.jpg

I don't know of any find & replace method that will achieve this.
 
Upvote 0
Peter, could you just delete this thread? I'll make a new post and try to explain it better. I don't want to make yet another revision to this thread and make it convoluted.
 
Upvote 0
We don't generally delete threads unless they contain spam or other inappropriate content. However, I have closed this thread so it cannot be added to. Proceed with your new thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,587
Messages
6,179,741
Members
452,940
Latest member
rootytrip

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