0

I'm trying to get data from an array into a non-contiguous named range. I keep ending up with the first cell of data is all of the named range cells. I think I hurt my brain. I'm looking at my code and not even sure why I wrote it, so I'll just leave that part out.

I need data copied from A2:I2 then pasted into named range "blah" (B2,D2,F2,B4,D4,F4,B6,D6,F6)

Can someone point me in the correct direction please? It's actually way more complicated than this, but I can't seem to get this part working. Thanks for any insight.

1
  • Could you share the piece of code that produces unexpected results? Commented Aug 12, 2014 at 0:09

2 Answers 2

1

Consider this as an example:

Sub MoveData()
    Dim r1 As Range, r2 As Range, r As Range, _
        indx As Long, ary()
    Set r1 = Range("A2:I2")
    Set r2 = Range("B2,D2,F2,B4,D4,F4,B6,D6,F6")
    r2.Name = "blah"

    ary = r1

    indx = 1
    For Each r In Range("blah")
        r.Value = ary(1, indx)
        indx = indx + 1
    Next r
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

That works perfectly. Was hoping to do it by the range names and keep it dynamic instead of hard coding the cell locations, but this will get the job done and I need to be finished with this project. Thank you for your help!
0

There are multiple ways of referencing cells in excel cell these are relative or absolute or semi-absolute. Have you tried using another style.

Or

can you use an offset function like this in the next column =OFFSET($a2,0,2*(row()-1))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.