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">
</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 -->
</TD></TR></TBODY></TABLE>
 

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,953
Office Version
365, 2010
Platform
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,953
Office Version
365, 2010
Platform
Windows
Code:
Sub test()
Dim col1 As Long, col2 As Long
col1 = ActiveCell.Column: col2 = 17
Range(Columns(col1), Columns(col2)).Select
End Sub
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,532
Messages
5,511,872
Members
408,866
Latest member
palchitech

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top