View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Multiple Discrete Columns Selection

Dim y as Range, rng as Range, col as Range
set y = Range("H:H,Q:S")
for each col in Activesheet.UsedRange.Columns
if intersect(col,y) is nothing then
if rng is nothing then
set rng = col
else
set rng = union(rng,col)
end if
End if
Next
' if you want the entire column
if not rng is nothing then
set rng = rng.entireColumn
msgbox rng.Address
End if

--
Regards,
Tom Ogilvy


"kaon " wrote in message
...
Thx for quick reply.

One more question.
Suppose I declare the range Y to be the above one mentioned. How can I
intersect the used range with the range Y so that other columns is
selected?

To illustrate:
A B C <-- Column C is selected to be range Y
Now I want to select columns A and B, not C to be selected.

Thanks.


---
Message posted from http://www.ExcelForum.com/