Tell me please, is there a way to set a range of non-adjacent columns with a single command?

For example, Range ("L9: M" + CStr (n1)). Copy. I would like to take column N instead of column M, i.e. jump over the column. To take each separately is not entirely satisfied.

    2 answers 2

    Can. Only the string concatenation character in VBA not + , but the ampersand character is & .

    Select multiple columns:

     ' Выделяет столбцы A, B и C Range("A:A, C:C, E:E").Select 

    Select area:

     Range(Cells(1, 1), Cells(3, 3)).Select ' То же, что и Range("A1:B3").Select 

    Select different columns, cells and areas:

     Range("A:A, F3, E7:F9").Select ' То же, что и Range("A:A, F" & CStr(3) & ", E" & CStr(7) & ":F" & CStr(9)).Select 

      If further non-one-time actions are assumed with non-adjacent ranges, it makes sense to assign a range to a variable:

       Dim r As Range Set r = Range("A2:A5, F3, E7:F9") r.Select 

      In the process, the range can be changed:

       Sub TestRng() Dim r As Range Set r = Range("A2:A5, F3, E7:F9") ' создаем диапазон r.Value = 1 Set r = Union(r, Range("C7, D4:D8")) ' пополняем диапазон r.Interior.Color = RGB(200, 100, 100) Set r = Nothing ' освобождаем память End Sub