views:

157

answers:

2

Is it possible to add cells to a range? Because the cells i need, aren't next to each other.

Example:
I need to add the cells with x in one range

x 0 x x
x 0 x x
x 0 x x

Is this possible? and if so, how?

Thanks

+1  A: 

Try this

VBA:

Range("B26,B19,B13").Select

C#

Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("B26,B19,B13", Type.Missing);
Tommy
A: 

VBA

Option Explicit

Sub ShowAreaUse()

    Dim oRange As Range
    Dim oArea As Range

    'create range with four cells
    Set oRange = Range("C9,E22,F15,I6")

    Debug.Print "Range with four area ranges"
    Debug.Print oRange.Address

    For Each oArea In oRange.Areas
        Debug.Print "    " + oArea.Address
    Next

    'add more cells
    Set oRange = Range(oRange.Address + ",A1:B10")

    Debug.Print "Range with added cells"
    Debug.Print oRange.Address

    For Each oArea In oRange.Areas
        Debug.Print "    " + oArea.Address
    Next

    Debug.Print "Dump Range Cells"

    For Each oArea In oRange
        Debug.Print "    " + oArea.Address
    Next

End Sub
AMissico