Simple VBA - Find and replace?

acnation

New Member
Joined
Aug 25, 2013
Messages
1
This seems like a fairly basic task, but I'm fairly new to VBA and I'm still learning the appropriate syntax. In a simplified way it goes like this.
I want to create a macro that takes the stores three different variables that the user types into an input value box.
V1, V2, V3
I need the macro to do the following.

  • 1. Ask user to variable V1, V2, V3.
  • 2. Find V2, and replace it with V3.
  • 3. Then (order is important) Find V1 and replace it with V2.
Example:

  • 1. Enter: V1 = May, V2 = June, V3 = July
  • 2. Find June and replace it with July
  • 3. Find May and replace it with June
This seems fairly simple but I'm not sure how to go about with it. Any help would be greatly appreciated. Thanks so much!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
If you record a macro of you doing a find replace, Control + H, stop recording after completing both functions.

Have particular cells that contains V1 V2 and V3.
Let's say they are in Cell V1, V2 and V3.
Have Range("V1").Value = V1
Range("V2").Value = V2
Range("V3").Value = V3

Then when you locate the find/replace code, you replace the "looked for" with V2 and "Replace with" with V3, then "looked for" with V1, and "Replaced with" with V2.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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