looping thru named ranges

G

Greg

Hi,

I have a bunch of pairs of named ranges, all of them consist of some
leading identifier followed by LIVE or HARD, for instance spLIVE, spHARD;
RussellLIVE, RussellHARD, etc.

How would I loop through the range collection and copy/ paste values each
LIVE range into respective HARD range?

Thank you,
 
J

JE McGimpsey

One way:

Dim nmTest As Name
Dim rDest As Range
Dim rSource As Range
Dim sTest As String
For Each nmTest In ActiveWorkbook.Names
sTest = nmTest.Name
If sTest Like "*LIVE" Then
sTest = Left(sTest, Len(sTest) - 4) & "HARD"
On Error Resume Next
Set rSource = nmTest.RefersToRange
Set rDest = ActiveWorkbook.Names(sTest).RefersToRange
On Error GoTo 0
If Not rDest Is Nothing And Not rSource Is Nothing Then _
rSource.Copy Destination:=rDest
End If
Next nmTest
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top