Results 1 to 4 of 4

Thread: split range address into individual cell addresses

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    46

    split range address into individual cell addresses

    hi,

    Given a range say, "A1:E1", i need a formula OR a single line of code to return a string of cells "A1","B1","C1","D1","E1". I do not want to use helper columns if it is a worksheetfunction, OR loops if its a VBA code.

    has anyone tried something like this?

    Function SplitRange(myRng as Range) as String
    .....
    .....
    SplitRange= .....
    End Function

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: split range address into individual cell addresses

    very easy in vba, but not without loop
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    46

    Re: split range address into individual cell addresses

    well, i know how to do it using a loop, but i need a one-liner code without a loop OR an some worksheet array formula that returns an array of strings, which i can then use it as a single line of code into my VBA code.

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    46

    Re: split range address into individual cell addresses

    i worked out this worksheet Array formula:

    ={SUBSTITUTE(CELL("address",INDEX(A1:E1,1,COLUMN(A1:E1))),"$","")}

    which gives me correct result i.e. "A1","B1","C1","D1","E1" across multiple cells.

    But question is: how do you i convert this into a single-line code in VBA? as far as i know, the worksheet CELL function does not have any equivalent in VBA.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width