Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default select non contiguos columns by variable name

I have integer variables that define several columns of interest in a
worksheet. How do I select multiple non contiguous columns?

Example

parts = 3 ' column 3 has parts info
dates = 6 ' column 6 has date info
cost = 10 ' column 10 has cost info

columns(parts, dates, cost).Select this statement does not work

TIA


John Keith

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default select non contiguos columns by variable name

Hi,

Try this :

Range("parts, dates, cost").Select




"John Keith" a écrit dans le message de groupe de discussion :
...
I have integer variables that define several columns of interest in a
worksheet. How do I select multiple non contiguous columns?

Example

parts = 3 ' column 3 has parts info
dates = 6 ' column 6 has date info
cost = 10 ' column 10 has cost info

columns(parts, dates, cost).Select this statement does not work

TIA


John Keith


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default select non contiguos columns by variable name

With ActiveSheet
Union(.Columns(parts), .Columns(dates), .Columns(cost)).Select
End With

But remember, it's very rare where you actually have to select a range to work
with it.

John Keith wrote:

I have integer variables that define several columns of interest in a
worksheet. How do I select multiple non contiguous columns?

Example

parts = 3 ' column 3 has parts info
dates = 6 ' column 6 has date info
cost = 10 ' column 10 has cost info

columns(parts, dates, cost).Select this statement does not work

TIA


John Keith


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default select non contiguos columns by variable name

On Sat, 23 Jan 2010 17:55:31 -0500, "michdenis"
wrote:

Try this :

Range("parts, dates, cost").Select


I did try that and it did not work. But thank you for looking.


John Keith

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default select non contiguos columns by variable name

On Sat, 23 Jan 2010 18:14:27 -0600, Dave Peterson
wrote:

With ActiveSheet
Union(.Columns(parts), .Columns(dates), .Columns(cost)).Select
End With

But remember, it's very rare where you actually have to select a range to work
with it.


Dave,

Thank you that worked perfectly. And yes, I was able to merge the next
line that began Selection.

What are the pros/cons to using Select?


John Keith



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default select non contiguos columns by variable name

The cons are that you have to select something to work with it. The code is
difficult to read/modify.

The pros are that you can use what the macro recorder gave you. But that
recorded macro is probably very messy to understand.

John Keith wrote:

On Sat, 23 Jan 2010 18:14:27 -0600, Dave Peterson
wrote:

With ActiveSheet
Union(.Columns(parts), .Columns(dates), .Columns(cost)).Select
End With

But remember, it's very rare where you actually have to select a range to work
with it.


Dave,

Thank you that worked perfectly. And yes, I was able to merge the next
line that began Selection.

What are the pros/cons to using Select?

John Keith


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default select non contiguos columns by variable name


| I did try that and it did not work. But thank you for looking.

Range("parts, dates, cost").Select

*** it works if "parts", "dates" and "cost" are names not variables
representing a column number as it was the case in your question.
I simply misinterpreted your request !




John Keith

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default select non contiguos columns by variable name

On Mon, 25 Jan 2010 23:12:54 -0500, "michdenis"
wrote:


| I did try that and it did not work. But thank you for looking.

Range("parts, dates, cost").Select

*** it works if "parts", "dates" and "cost" are names not variables
representing a column number as it was the case in your question.
I simply misinterpreted your request !


Ah, thank you. Someday I'm going to use range names and I'll add this
to my bag of tricks.


John Keith

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
error - select method failed - (columns.select) PBcorn Excel Programming 3 May 19th 08 10:49 AM
"Print titles must be contiguos and complete rows or columns?" Juan Diaz L Excel Discussion (Misc queries) 1 January 24th 08 04:47 PM
Select Variable Number of Columns Mike H. Excel Programming 4 July 9th 07 05:46 AM
select columns by variable Jack Excel Programming 4 November 29th 05 09:09 PM
Non-Contiguos Range Iteration Matthew Wieder Excel Programming 8 March 4th 04 12:54 PM


All times are GMT +1. The time now is 04:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"