Using a loop function to copy and paste a list of named ranges

Spotycus

New Member
Joined
Dec 8, 2015
Messages
25
Hello,

I hope people find this idea an interesting idea and easy to solve. Recently I came across the following code which has been very useful as a find and replace tool.

Code:
Dim Rng1 As Range
Dim InputRng1 As Range, ReplaceRng1 As Range
xTitleId = "Parkway Data Cleanser"

'(I changed these lines to text to disable the inputbox but still keep the option for later)
'Set InputRng1 = Application.Selection
'Set InputRng1 = Application.InputBox("Original Range ", xTitleId, InputRng.Address, Type:=8)
'Set ReplaceRng1 = Application.InputBox("Replace Range :", xTitleId, Type:=8)

Set InputRng1 = Range("OldData")
Set ReplaceRng1 = Range("NewData")
For Each Rng1 In ReplaceRng1.Columns(1).Cells
    InputRng1.Replace What:=Rng1.Value, Replacement:=Rng1.Offset(0, 1).Value
Next Rng1
 Application.ScreenUpdating = False

It seems like I always need to copy different ranges of information from one place to another, and quite often I will need to do that multiple times.

Code:
Application.Goto Reference:="ACCNT"
    Application.CutCopyMode = False
    Selection.Copy
    Application.Goto Reference:="Line_Account"
    ActiveSheet.Paste
    
    Range("iifcreditformula").Select
    Selection.Copy
    Application.Goto Reference:="Credit"
    ActiveSheet.Paste
    
    Application.Goto Reference:="IIFdebitformula"
    Application.CutCopyMode = False
    Selection.Copy
    Application.Goto Reference:="Debit"
    ActiveSheet.Paste
    
    Application.Goto Reference:="IIFcreditformula"
    Application.CutCopyMode = False
    Selection.Copy
    Application.Goto Reference:="credit"
    ActiveSheet.Paste


Could someone suggest a better method that would allow me to setup a table of values such as column A would have my selected range to copy and column B would have my selected range to paste to. It would 10x better if column C would be for the paste method (PasteValues, PasteFormulas, etc.)

Thank you for the knowledge and the help!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
U don't understand the code... the No Copy and Pasting was the most nb part. Depends what U want to do. U can just directly code...
Range("OldData") = Range("NewData") for example. Then as suggested, use a loop of the range to do whatever... which in this code case seems to be moving all of the values in the 2nd column of the range to the 1st column (or viceversa). I'm really not clear what "Replace" does and why it would be needed? If anyone has any additional learning available on the topic, that would probably help both of us. HTH. Dave
 
Upvote 0
I apologize for the confusion, the first part of code was just an example of a loop that I found very useful and wanted to mimic the concept. I do not need to replace anything. I want to be able to copy and paste a specific range of data to a new location. I am trying to create a variety of different data converters that each have to be mapped differently for them to properly import. Instead of having to go in and change the Range ("OldData") = Range("NewData") within the code 10+ times each time it changes, I would like to create a user form where I input the different range values and their new destinations. An example of what I am trying to do would be to change an .IIF file over to a .QBO file. Again sorry for my ignorance but I am having fun while I learn.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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