ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting multiple columns (https://www.excelbanter.com/excel-programming/286837-selecting-multiple-columns.html)

Kiloran[_2_]

Selecting multiple columns
 
I can select Column A with either Columns("A").Select or Columns(1).Select

I can select Columns A-C with Columns("A:C").Select. However,
Columns(1:3).Select does not work.

How can I select a range of columns using a numeric reference?

--Alan



Tom Ogilvy

Selecting multiple columns
 
Columns(1).Resize(,3).Select


Range(Columns(1),Columns(3)).Select

Are two ways.

--
Regards,
Tom Ogilvy


"Kiloran" wrote in message
...
I can select Column A with either Columns("A").Select or Columns(1).Select

I can select Columns A-C with Columns("A:C").Select. However,
Columns(1:3).Select does not work.

How can I select a range of columns using a numeric reference?

--Alan





Shailesh Shah[_2_]

Selecting multiple columns
 
Hi Alan,

Try something like this,

Sub SelectColumn(stcol As Integer, lastcol As Integer)

If lastcol = stcol And lastcol 0 And stcol 0 And stcol <= 256 And
lastcol <= 256 Then

Columns(stcol).Resize(, lastcol - stcol + 1).Select

Else
'for demo purpose

MsgBox "Couldn't select Col."

End If

End Sub

Sub test()
SelectColumn 1, 3 ' A-C
End Sub



Regards,
Shah Shailesh
http://members.lycos.co.uk/shahweb/


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 12:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com