change input range in VBA code

perahlgren

New Member
Joined
Feb 7, 2018
Messages
3
Hi,

I want to set the input range and the replace range to fixed. Is that possible?

//Per

Sub MultiFindNReplace()
'Update 20140722
Dim Rng As Range
Dim InputRng As Range, ReplaceRng As Range
xTitleId = "ersätt"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Original Range ", xTitleId, InputRng.Address, Type:=8)
Set ReplaceRng = Application.InputBox("Replace Range :", xTitleId, Type:=8)
Application.ScreenUpdating = False
For Each Rng In ReplaceRng.Columns(1).Cells
InputRng.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value
Next
Application.ScreenUpdating = True
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi & welcome to the board.

yes it's possible, what ranges do you want to use?
 
Upvote 0
Hi perahlgren and Welcome to the Board! Sure it's possible. Care to share what the fixed input and replace ranges are? Dave
 
Upvote 0
Hi Thanks alot,
The translation table is in sheet1 range J2:K60 and the original data is in sheet2 column F.
//Per
 
Upvote 0
Try
Code:
Sub MultiFindNReplace()
'Update 20140722
   Dim Rng As Range
   Dim InputRng As Range, ReplaceRng As Range
   
   Set InputRng = Sheets("Sheet1").Range("J2:K60")
   Set ReplaceRng = Sheets("Sheet2").Range("F1", Sheets("Sheet2").Range("F" & Rows.Count).End(xlUp))
Application.ScreenUpdating = False
   For Each Rng In ReplaceRng
      InputRng.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value
   Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,216,014
Messages
6,128,280
Members
449,436
Latest member
blaineSpartan

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