column selection in vba

aviadht

Board Regular
Joined
Aug 7, 2008
Messages
91
<TABLE class=tborder id=post2395995 cellSpacing=0 cellPadding=6 width="100%" align=center border=0><TBODY><TR vAlign=top><TD class=alt1 id=td_post_2395995 style="BORDER-RIGHT: #ffffff 1px solid">I want to select columns with parameters

parameter 1: col1
parameter 2:col2

and the next one not working: columns(col1,col2).select

why ?

Aviad
<!-- / message --></TD></TR><TR><TD class=alt2 style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #ffffff 1px solid">
user_online.gif
</TD><TD class=alt1 style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #ffffff 0px solid; BORDER-BOTTOM: #ffffff 1px solid" align=right><!-- controls -->
progress.gif
</TD></TR></TBODY></TABLE>
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Its rarely necessary to select.

But here you go:

Code:
Sub test()
Dim col1 As Long, col2 As Long
col1 = 5: col2 = 17
Range(Columns(col1), Columns(col2)).Select
End Sub
 

aviadht

Board Regular
Joined
Aug 7, 2008
Messages
91
ok, thank you..it works..but now i have another question (-:

asume that i'm on activecell and i want the parameter (integer) "colnum" to get te activecell column number. for example column b number is 2.

how can i do that ?

Regards,
Aviad
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Code:
Sub test()
Dim col1 As Long, col2 As Long
col1 = ActiveCell.Column: col2 = 17
Range(Columns(col1), Columns(col2)).Select
End Sub
 

Forum statistics

Threads
1,176,344
Messages
5,902,597
Members
434,981
Latest member
sheils

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top