named range = named ranged

ndendrinos

Well-known Member
Joined
Jan 17, 2003
Messages
1,694
Named range “toplist” is contiguous [A1:L1]
Named range ‘mylist” is non contiguous
(“A24,B23,A16,D20,E12,F27,E16,A15,K14,L20,P21,M19")

On sheet1
I’m looking for code that looks something like this:
Code:
[mylist].Value = [toplist].Value

My understanding is that because one range is non contiguous there needs to be a loop
and I need assistance

something like this
Code:
Sub test()
Dim rngCell As Range
Dim lngCount As Long
Dim aTemp()

    ReDim aTemp(0)
    lngCount = 0
    
    For Each rngCell In [toplist]
        aTemp(UBound(aTemp)) = rngCell
        ReDim Preserve aTemp(UBound(aTemp) + 1)
    Next rngCell
    
    ReDim Preserve aTemp(UBound(aTemp) - 1)
   


    With Worksheets("sheet1")
        For Each rngCell In [mylist]
        rngCell = aTemp(lngCount)
        lngCount = lngCount + 1
    Next rngCell
End With
End Sub
 
Last edited:
Clarification: I've never been to Greece, all my immediate family members going back five generations that we were able to trace were all born and raise in Egypt and educated in French.
From what I hear though you better watch your back (I'm a joker as well)

Now to serious business:
I'm trying the reverse that is:
What ever is typed in range [mylist] needs to populate range[toplist]
Somehow I'm having difficulties in doing so.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
reversed as per #7 like this:
Code:
Sub helloREVERSE()
Dim rngCell As Range
Dim lngCount As Long
Dim aTemp()

    ReDim aTemp(0)
    lngCount = 0
    
    For Each rngCell In [mylist]
        aTemp(UBound(aTemp)) = rngCell
        ReDim Preserve aTemp(UBound(aTemp) + 1)
    Next rngCell
    
    ReDim Preserve aTemp(UBound(aTemp) - 1)
   


    With Worksheets("search")
        For Each rngCell In [toplist]
        rngCell = aTemp(lngCount)
        lngCount = lngCount + 1
    Next rngCell
End With
End Sub

and it works . Still would prefer Richard's simpler code to achieve same
 
Upvote 0
Just a simple amendment to the code:

Code:
Dim i As Long
Dim rngCell As Range

i = 1
 
For Each rngCell In [toplist]
 
  Range("mylist")(i) = rngCell.Value
 
  i = i + 1
 
Next
 
Upvote 0
sorry Richard. your last suggestion does not work.
what it does is delete [A24] that is the first cell if named range "mylist"
it does not paste anything to named range "toplist"
maybe again I'm not explaining it well:

toplist range is empty
I populate cells in range mylist
need to copy same and paste in range toplist

thanks
 
Upvote 0
I think this way is OK now
Code:
Sub helloREVERSE()
Dim i As Long
Dim rngCell As Range
i = 1
For Each rngCell In [mylist]
  Range("toplist")(i) = rngCell.Value
  i = i + 1
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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