Referencing a named range within Loop

DaWookie

Board Regular
Joined
Aug 16, 2011
Messages
50
A named range of 6 cells ("MyRange") contains the names of 6 other named single-cell ranges (locations) within a worksheet.

Assuming a preceding loop that ultimately results in a 'selection.cut' of a certain range, how would I:

1. Loop through MyRange and then paste the preceding selection to that location? My effort is provided below, which bombs on the Application.Goto Range(rngLocation). I feel like I need to indirectly reference the names within MyRange.

Code:
Sub Sample()

Dim MyRange As Range
Dim RngCell As Range
Dim rngLocation As Range

'Preceding loop code...Selection.Cut
        
       For Each RngCell In Range("MyRange")
            Set RngCell = rngLocation
            Application.Goto Range(rngLocation)
            ActiveSheet.Paste
            Application.CutCopyMode = False
        Next RngCell

'Back into outer loop...End If
        iterator = iterator + 1
    Loop
            
End Sub
Thanks -w0ok-
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Welcome to the MrExcel board!

1. You don't appear to have used it but you have declared 'MyRange' as Range in your code. Since myRange is already a named range in your worksheet, I suggest that you don't use the same name as a variable in your code.

2. From what I can tell, I think you just have this the wrong way around
Code:
Set RngCell = rngLocation
Try changing that to
Code:
Set rngLocation = RngCell
 
Upvote 0

Forum statistics

Threads
1,224,608
Messages
6,179,872
Members
452,949
Latest member
Dupuhini

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