ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   multiple range (https://www.excelbanter.com/excel-discussion-misc-queries/38214-multiple-range.html)

nowfal

multiple range
 

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


--
nowfal
------------------------------------------------------------------------
nowfal's Profile: http://www.excelforum.com/member.php...o&userid=10003
View this thread: http://www.excelforum.com/showthread...hreadid=392092


Dave Peterson

How about:

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

No need to select first.

nowfal wrote:

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

--
nowfal
------------------------------------------------------------------------
nowfal's Profile: http://www.excelforum.com/member.php...o&userid=10003
View this thread: http://www.excelforum.com/showthread...hreadid=392092


--

Dave Peterson

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

"nowfal" wrote:


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


--
nowfal
------------------------------------------------------------------------
nowfal's Profile: http://www.excelforum.com/member.php...o&userid=10003
View this thread: http://www.excelforum.com/showthread...hreadid=392092



nowfal


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


--
nowfal
------------------------------------------------------------------------
nowfal's Profile: http://www.excelforum.com/member.php...o&userid=10003
View this thread: http://www.excelforum.com/showthread...hreadid=392092


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.


nowfal wrote:

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

--
nowfal
------------------------------------------------------------------------
nowfal's Profile: http://www.excelforum.com/member.php...o&userid=10003
View this thread: http://www.excelforum.com/showthread...hreadid=392092


--

Dave Peterson

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


--
nowfal
------------------------------------------------------------------------
nowfal's Profile: http://www.excelforum.com/member.php...o&userid=10003
View this thread: http://www.excelforum.com/showthread...hreadid=392092


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").Cl earContents

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



nowfal wrote:

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

--
nowfal
------------------------------------------------------------------------
nowfal's Profile: http://www.excelforum.com/member.php...o&userid=10003
View this thread: http://www.excelforum.com/showthread...hreadid=392092


--

Dave Peterson

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


--
nowfal
------------------------------------------------------------------------
nowfal's Profile: http://www.excelforum.com/member.php...o&userid=10003
View this thread: http://www.excelforum.com/showthread...hreadid=392092


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").Cl earContents

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

nowfal wrote:

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

--
nowfal
------------------------------------------------------------------------
nowfal's Profile: http://www.excelforum.com/member.php...o&userid=10003
View this thread: http://www.excelforum.com/showthread...hreadid=392092


--

Dave Peterson

Dave Peterson

More problems with the alfabet/fingers!

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

Dave Peterson wrote:

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").Cl earContents

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

nowfal wrote:

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

--
nowfal
------------------------------------------------------------------------
nowfal's Profile: http://www.excelforum.com/member.php...o&userid=10003
View this thread: http://www.excelforum.com/showthread...hreadid=392092


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 01:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com