How To Select Multiple Cells In Excel Vba

To select multiple cells in Excel VBA, you can use the Range object and the Select method. The Range object represents a cell, a range of cells, or a selection in Excel. Here’s an example of how to select multiple cells:

<script>
Sub SelectMultipleCells()
    Dim rng As Range
    
    ' Selecting a single cell
    Range("A1").Select
    
    ' Selecting a range of cells
    Range("A1:B2").Select
    
    ' Selecting non-adjacent cells
    Set rng = Range("A1,B3,D5")
    rng.Select
End Sub
    </script>

In the above example, the first two lines of code show how to select a single cell (A1) and a range of cells (A1 to B2). To select non-adjacent cells, you can use the Set keyword to create a Range object with multiple cell addresses.

Leave a comment