Home |
Search |
Today's Posts |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Another way just for curiosity, but I'd go with Leo's
Sub MultiCol() Dim bAdj As Boolean Dim i As Long Dim sAddr As String Dim rng As Range Dim varr varr = Array(1, 5, 8, 9, 10, 12) ' OP's 'varr = Array(2, 10, 27, 53, 105, 256) 'another test sAddr = "C[" For i = LBound(varr) To UBound(varr) - 1 'ought union later if any adjacent columns If varr(i + 1) = varr(i) + 1 Then bAdj = True 'offset from Col-1 so subtract 1 sAddr = sAddr & varr(i) - 1 & "],C[" Next sAddr = sAddr & CStr((varr(UBound(varr)) - 1)) & "]" sAddr = Application.ConvertFormula(sAddr, xlR1C1, xlA1, , Range("a1")) If bAdj = True Then Set rng = Union(Range(sAddr), Range(sAddr)) Else Set rng = Range(sAddr) End If rng.Select Debug.Print rng.Address(0, 0) End Sub This would fail with over 36 3-digit column numbers due to address length limit. Regards, Peter T "c mateland" wrote in message oups.com... Excel 2003 What is the syntax for selecting multiple noncontiguous columns using column numbers instead of letters? Example, I only know the column numbers I want selected are 3, 5, 8-10, and 12. Thanks. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Average numbers in noncontiguous columns ignoring 0's. | Excel Worksheet Functions | |||
Select Number of Columns and Print Macro | Excel Discussion (Misc queries) | |||
Using Multiple, Noncontiguous Ranges in COUNTIF? | Excel Discussion (Misc queries) | |||
Print titles: can noncontiguous columns at left be printed & how? | Excel Worksheet Functions | |||
VBA to select multiple columns | Excel Programming |