+ Reply to Thread
Results 1 to 4 of 4

Using Names

Hybrid View

pctuk Using Names 01-15-2010, 07:52 AM
pike Re: Using Names 01-15-2010, 08:27 AM
pctuk Re: Using Names 01-15-2010, 09:02 AM
pike Re: Using Names 01-15-2010, 09:35 AM
  1. #1
    Registered User
    Join Date
    01-05-2010
    Location
    UK
    MS-Off Ver
    Excel 2002
    Posts
    6

    Question Using Names

    Hi

    I have 2 defined ranges named 'X' and 'Y' (via Insert>Name>Define). X is A1:F1. Y is B1:F1.

    I'm quite new to Names, so aren't familiar with the VBA.

    So far I've manged to clear the range via
    ThisWorkbook.Names("X").RefersToRange.ClearContents
    I'd now like code that copies each of the values in Y into X. However, I need to do this cell-by-cell, rather than in 1 go. This is because there are linkages between rows A and B. Ie, changing cell A1 will result in a change to B2, changes to A2 will change C3, etc.

    Hope this is clear, but please let me know if it isn't.

    Thanks in advance

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Using Names

    Hi pctuk
    use something like
    Sub ptest()
    Z = ThisWorkbook.Names("x").RefersToRange.Value
    For Each w In Z
    Debug.Print w
    Next
    End Sub
    this result will be in the Immediate pane
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    01-05-2010
    Location
    UK
    MS-Off Ver
    Excel 2002
    Posts
    6

    Re: Using Names

    Thanks very much for the reply. Just for reference, I think I've cracked it:-

    Sub Macro()
        Dim Destination As Range
        Dim Source As Range
        
        Set Destination = ThisWorkbook.Names("X").RefersToRange
        Set Source = ThisWorkbook.Names("Y").RefersToRange
        
        Destination.ClearContents
            
        For i = 1 To 10 Step 1
           Destination(1, i) = Source(1, i)
           Next i
    End Sub
    Paul

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Using Names

    Excellent!
    You can also
    use Ubound to find the last value
    Sub ptest()
    Z = ThisWorkbook.Names("x").RefersToRange.Value
    For w = 1 To UBound(Z)
    Debug.Print w
    Next
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1