简体   繁体   中英

Excel VBA - Split array and return as list

I have a range of cell addresses saved as a range, which I then want to return as a list of individual cell addresses. I can't seem to find anything online that says this is posible, does anyone know otherwise?

Many thanks

What I have got so far:

Function AN()

Dim CellRange As String Dim a() As String Dim intCount As Integer

Dim strTemp

For Each C In ActiveCell.Offset(0, 0).Range("A1:A46")
    If C = "" Then
        C.Select
        CellRange = Range("C" & ActiveCell.Row, ActiveCell.Offset(0, -1)).Address
        a = split(CellRange)
            For intCount = LBound(a) To UBound(a)
            MsgBox a(intCount)

            Next

This gives me the two extremes of the range, but not the cells in between. Split doesn't seem to be working - I'm still getting to grips with it so please forgive any errors there .. it's been a long day!

Here is one way to convert a range into a string of addresses, comma-separated:

Sub dural()
    Dim r As Range, s As String
    Set r = Range("A1,B9,D13,J78,l987")
    s = r.Address(0, 0)
    MsgBox s
End Sub

You can make this into an array of strings using Split():

Sub dural()
    Dim r As Range, s As String
    Set r = Range("A1,B9,D13,J78,l987")
    s = r.Address(0, 0)
    MsgBox s
    ary = Split(s, ",")
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM