multiple range

N

nowfal

HI,
I would like to know to selected multiple ranges and clear the
contents
presently my code is like this:

Range("C2:L2").Select
Selection.ClearContents
Range("N2").Select
Selection.ClearContents
ActiveWindow.SmallScroll ToRight:=6
Range("O2:R2").Select
Selection.ClearContents
Range("T2:W2").Select
Selection.ClearContents

I wanted to writed in one line like:

Range("C2:L2","N2","O2:R2","T2:W2").Select
Selection.ClearContents


Any possibility.
thanks in advance
regards
nowfal
 
D

Dave Peterson

How about:

Range("C2:L2,N2,O2:R2,T2:W2").ClearContents

No need to select first.
 
F

FSt1

hi
As you wished.
Range("C2,C2:L2,N2,O2:R2,T2:W2").Select

But you do know that N2,O2:R2 is the same as N2:R2.

Regards
FSt1
 
N

nowfal

Hi Mr.Dave Peterson,
Done, thank u very much. It saves lot
of time while running the macro.
with regards
nowfal
 
D

Dave Peterson

Did you see FSt1's note:

But you do know that N2,O2:R2 is the same as N2:R2.

Sometimes, cleaning this kind of thing up when you notice it means you won't be
wondering why you did it that way before.
 
N

nowfal

Hi Mr.Dave Peterson,
I saw his(FSt1) question, but it is
not inside that. N2 is separately cleaning , i wanna to avoid 5 cells
from clean ie. M2,S2,X2,AC2,AH2 b coz it contains formula that too the
macro unprotecting the sheet on the begining.

(Range("C2:H2,J2:L2,N2,O2:R2,T2:W2,Y2:AB2,AD2:AG2").ClearContents)

.. As u said to be frank , 3 months before i was nothing (still i am a
KG student comparing guys like u) now atleast i can say i have done
some good work, which is using almost 50 people in different branches
of my company. So better portion of the credit goes to guys like u
Dave, Bob, etc etc . So keep it up helping others.
Thanks a lot
with regards


nowfal
 
D

Dave Peterson

Fstl's point was that the cell N2 is inside the range O2:R2, so:

This formula
Range("C2:H2,J2:L2,N2,O2:R2,T2:W2,Y2:AB2,AD2:AG2").ClearContents
is equivalent to:
Range("C2:H2,J2:L2,O2:R2,T2:W2,Y2:AB2,AD2:AG2").ClearContents

You wouldn't have to specify N2, since it's in the middle of O2:R2.
 
N

nowfal

Hi Dave,
First of all, i dont like to argue with my teacher. So it
is not an argument, just to reply thats all.
AB CDEFGH I JKL M N OPQR STUVWXYZ.

I think u got it. N is not in the middle of OPQR. And I seperated the
N with a coma before and after. I think this confusion started by
Mr.Fstl. After all I dont want to eat your valuable time. Thanks for
the reply.
with regards
nowfal
 
D

Dave Peterson

You are absolutely correct. (Stupid alphabet changes for me sometimes.)

Bun N2:R2 would include O2.

Range("C2:H2,J2:L2,N2:R2,T2:W2,Y2:AB2,AD2:AG2").ClearContents

(I just screwed up FStl's note. It was my error, not his.)
 
D

Dave Peterson

More problems with the alfabet/fingers!

Bun N2:R2 would include O2.
should be:
But N2:R2 would include O2.
 
Top