Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default select uneven range

Try this statement...

Union(Range("B2:B3"), Range("C2:" & Range("C2").End(xlDown))).Select

Usually you don't have to select the cells in order to do things to them.
Perhaps this previous posting of mine (a response to another person using
Select/Selection type constructions) will be of some help to you in your
future programming...

Whenever you see code constructed like this...

Range("A1").Select
Selection.<whatever

you can almost always do this instead...

Range("A1").<whatever

In your particular case, you have this...

Range("C2:C8193").Select 'select cells to export
For Each r In Selection.Rows

which, using the above concept, can be reduced to this...

For Each r In Range("C2:C8193").Rows

Notice, all I have done is replace Selection with the range you Select(ed)
in the previous statement and eliminate the process of doing any
Select(ion)s. Stated another way, the Selection produced from
Range(...).Select is a range and, of course, Range(...) is a range... and,
in fact, they are the same range, so it doesn't matter which one you use.
The added benefit of not selecting ranges first is your active cell does not
change.

--
Rick (MVP - Excel)


"Jake" wrote in message
...
I would like to select a range from cells B2:B3 and from C2 to the last
contiguous cell below C2. I've tried currentregion and a few other pieces
of
code with now success.
Thanks,
Jake


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default select uneven range

thanks Rick,
I've made an error in my question. I want to set a range variable and I
realize I need the range B2:C2 to last contiguous cell in column C, not just
B2:B3.
I've tried this code:
Set rngDSUMCriteria = Range("B2"), Range("C2:" & Range("C2").End(xlDown))
but it has an error and I'm not sure why

"Rick Rothstein" wrote:

Try this statement...

Union(Range("B2:B3"), Range("C2:" & Range("C2").End(xlDown))).Select

Usually you don't have to select the cells in order to do things to them.
Perhaps this previous posting of mine (a response to another person using
Select/Selection type constructions) will be of some help to you in your
future programming...

Whenever you see code constructed like this...

Range("A1").Select
Selection.<whatever

you can almost always do this instead...

Range("A1").<whatever

In your particular case, you have this...

Range("C2:C8193").Select 'select cells to export
For Each r In Selection.Rows

which, using the above concept, can be reduced to this...

For Each r In Range("C2:C8193").Rows

Notice, all I have done is replace Selection with the range you Select(ed)
in the previous statement and eliminate the process of doing any
Select(ion)s. Stated another way, the Selection produced from
Range(...).Select is a range and, of course, Range(...) is a range... and,
in fact, they are the same range, so it doesn't matter which one you use.
The added benefit of not selecting ranges first is your active cell does not
change.

--
Rick (MVP - Excel)


"Jake" wrote in message
...
I would like to select a range from cells B2:B3 and from C2 to the last
contiguous cell below C2. I've tried currentregion and a few other pieces
of
code with now success.
Thanks,
Jake



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default select uneven range

The most obvious thing wrong with your code is you didn't use the Union
function with it. The Union function "joins" non-contiguous ranges together,
you just list each range that you want "joined" in a comma separated list.
There appears to be some problem with how you attempted to form those ranges
in the code you just posted; however, for what you now want, which appears
to be a contiguous range (which is markedly different from your original
question which dealt with "uneven", what I call non-contiguous, ranges), you
won't need the Union function at all.

Set rngDSUMCriteria = Range("B2:C" & Range("C2").End(xlDown).Row)

--
Rick (MVP - Excel)


"Jake" wrote in message
...
thanks Rick,
I've made an error in my question. I want to set a range variable and I
realize I need the range B2:C2 to last contiguous cell in column C, not
just
B2:B3.
I've tried this code:
Set rngDSUMCriteria = Range("B2"), Range("C2:" & Range("C2").End(xlDown))
but it has an error and I'm not sure why

"Rick Rothstein" wrote:

Try this statement...

Union(Range("B2:B3"), Range("C2:" & Range("C2").End(xlDown))).Select

Usually you don't have to select the cells in order to do things to them.
Perhaps this previous posting of mine (a response to another person using
Select/Selection type constructions) will be of some help to you in your
future programming...

Whenever you see code constructed like this...

Range("A1").Select
Selection.<whatever

you can almost always do this instead...

Range("A1").<whatever

In your particular case, you have this...

Range("C2:C8193").Select 'select cells to export
For Each r In Selection.Rows

which, using the above concept, can be reduced to this...

For Each r In Range("C2:C8193").Rows

Notice, all I have done is replace Selection with the range you
Select(ed)
in the previous statement and eliminate the process of doing any
Select(ion)s. Stated another way, the Selection produced from
Range(...).Select is a range and, of course, Range(...) is a range...
and,
in fact, they are the same range, so it doesn't matter which one you use.
The added benefit of not selecting ranges first is your active cell does
not
change.

--
Rick (MVP - Excel)


"Jake" wrote in message
...
I would like to select a range from cells B2:B3 and from C2 to the last
contiguous cell below C2. I've tried currentregion and a few other
pieces
of
code with now success.
Thanks,
Jake




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
Uneven column lookup brownti Excel Worksheet Functions 4 November 10th 09 11:25 PM
Compare 2 uneven colums MDI Anne Excel Discussion (Misc queries) 2 May 12th 09 01:32 PM
uneven ranges and coding Lori Excel Discussion (Misc queries) 6 November 19th 08 08:06 PM
Font looks uneven in spreadsheet Julie Excel Discussion (Misc queries) 0 March 22nd 07 09:45 PM
lookup with uneven columns [email protected] Excel Worksheet Functions 3 December 21st 06 07:32 PM


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

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

About Us

"It's about Microsoft Excel"