Multiple Discrete Columns Selection

K

kaon

Hi all,

Sorry for this stupid question.
If I want to select Columns H, Q, R, S at the same time, how can
achieve this by VBA code?

Thanks
 
W

William

Range("H:H,Q:S").Select
--
XL2002
Regards

William

[email protected]

| Hi all,
|
| Sorry for this stupid question.
| If I want to select Columns H, Q, R, S at the same time, how can I
| achieve this by VBA code?
|
| Thanks.
|
|
| ---
|
|
 
K

kaon

Thx for quick reply.

One more question.
Suppose I declare the range Y to be the above one mentioned. How can
intersect the used range with the range Y so that other columns i
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
 
T

Tom Ogilvy

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
 
Top