VBA: looping through a list of named ranges and pasting them to another sheet based on an address reference

StackOverflow https://stackoverflow.com/questions/14697628

質問

I am making some VBA code to help me do the following:

Paste a list of all named ranges Loop through the list and copy/select ranges based on the list Each selection will be pasted on another sheet given an address reference with a certain offset from that address

I am pretty new to VBA so I have put together some code that I think will do the trick but I am getting run time errors. Could someone help me troubleshoot or provide suggestions?

My code is here:

Sub RangeLoop()

Sheets("RANGEMATCH").Select
Range("A1").ListNames

Dim columnrange As Range
Dim m As Long
Dim address As Range

Set columnrange = Sheets("RANGEMATCH").Range("A:A").SpecialCells(xlConstants)

With columnrange
    For m = 1 To columnrange.Areas.Count
        Set address = Sheets("RANGEMATCH").Range(.Areas(m).Cells(1, 7).Value)
        Range(m).Copy Sheets("ETIE").Range(address.Offset(1, 10))
    Next
End With

End Sub

Here is an example workbook of what I am working with:

https://docs.google.com/spreadsheet/ccc?key=0AodOP_8DnJnFdHJoQ0xBM3JUUGJxT3EyRXN0T2ltUmc&usp=sharing

Any suggestion are appreciated.

役に立ちましたか?

解決

The Range() function expects a string variable. Either the name of a range or a cell reference like "A1"

Range(m).Copy Sheets("ETIE").Range(address.Offset(1, 10))

m is a number so that won't work. You'll need to reference the thing that you want to copy. I think that might just be your address object that you set in the line before:

address.Copy Sheets("ETIE").Range(address.Offset(1, 10))
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top