Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Select all cells NOT in a range

I'm trying to use SpecialCells to select all the non-blank cells in my range.
If my approach is correct please tell me how to complete my code, or if
there's a better way...

'my approach is to:
set Blanks=MyRange.SpecialCells(xlCellTypeBlanks)
'and then
set MyRange=intersect ( MyRange , [not blanks] )

'but I can't work out how to get [not blanks]

Thanks in advance
Rob
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Select all cells NOT in a range

Dim rng as Range, rng1 as Range, rng2 as Range
Set rng = MyRange
set rng1 = rng.specialcells(xlFormulas)
set rng2 = rng.Specialcells(xlconstants)
if not rng1 is nothing and not rng2 is nothing then
set rng = Union(rng1,rng2)
elseif not rng1 is nothing then
set rng = rng1
elseif not rng2 is nothing then
set rng = rng2
Else
set rng = nothing
end if
msgbox rng.Address

--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
I'm trying to use SpecialCells to select all the non-blank cells in my

range.
If my approach is correct please tell me how to complete my code, or if
there's a better way...

'my approach is to:
set Blanks=MyRange.SpecialCells(xlCellTypeBlanks)
'and then
set MyRange=intersect ( MyRange , [not blanks] )

'but I can't work out how to get [not blanks]

Thanks in advance
Rob



  #3   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Select all cells NOT in a range

Thanks Tom.

"Tom Ogilvy" wrote:

Dim rng as Range, rng1 as Range, rng2 as Range
Set rng = MyRange
set rng1 = rng.specialcells(xlFormulas)
set rng2 = rng.Specialcells(xlconstants)
if not rng1 is nothing and not rng2 is nothing then
set rng = Union(rng1,rng2)
elseif not rng1 is nothing then
set rng = rng1
elseif not rng2 is nothing then
set rng = rng2
Else
set rng = nothing
end if
msgbox rng.Address

--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
I'm trying to use SpecialCells to select all the non-blank cells in my

range.
If my approach is correct please tell me how to complete my code, or if
there's a better way...

'my approach is to:
set Blanks=MyRange.SpecialCells(xlCellTypeBlanks)
'and then
set MyRange=intersect ( MyRange , [not blanks] )

'but I can't work out how to get [not blanks]

Thanks in advance
Rob




  #4   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Select all cells NOT in a range

I'd really like this as a one liner, which would be posible if specialcells
didn't cause an error. Any ideas?

Union( MyRange.specialcells(xlFormulas) , Myrange.SpecialCells(xlconstants) )


"Tom Ogilvy" wrote:

Dim rng as Range, rng1 as Range, rng2 as Range
Set rng = MyRange
set rng1 = rng.specialcells(xlFormulas)
set rng2 = rng.Specialcells(xlconstants)
if not rng1 is nothing and not rng2 is nothing then
set rng = Union(rng1,rng2)
elseif not rng1 is nothing then
set rng = rng1
elseif not rng2 is nothing then
set rng = rng2
Else
set rng = nothing
end if
msgbox rng.Address

--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
I'm trying to use SpecialCells to select all the non-blank cells in my

range.
If my approach is correct please tell me how to complete my code, or if
there's a better way...

'my approach is to:
set Blanks=MyRange.SpecialCells(xlCellTypeBlanks)
'and then
set MyRange=intersect ( MyRange , [not blanks] )

'but I can't work out how to get [not blanks]

Thanks in advance
Rob




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Select all cells NOT in a range

No, you can't union with nothing.

I didn't make it multiline because I like to be verbose - in fact I left out
two critical lines

Dim rng as Range, rng1 as Range, rng2 as Range
Set rng = MyRange
On Error Resume Next
set rng1 = rng.specialcells(xlFormulas)
set rng2 = rng.Specialcells(xlconstants)
On Error goto 0
if not rng1 is nothing and not rng2 is nothing then
set rng = Union(rng1,rng2)
elseif not rng1 is nothing then
set rng = rng1
elseif not rng2 is nothing then
set rng = rng2
Else
set rng = nothing
end if


--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
I'd really like this as a one liner, which would be posible if

specialcells
didn't cause an error. Any ideas?

Union( MyRange.specialcells(xlFormulas) ,

Myrange.SpecialCells(xlconstants) )


"Tom Ogilvy" wrote:

Dim rng as Range, rng1 as Range, rng2 as Range
Set rng = MyRange
set rng1 = rng.specialcells(xlFormulas)
set rng2 = rng.Specialcells(xlconstants)
if not rng1 is nothing and not rng2 is nothing then
set rng = Union(rng1,rng2)
elseif not rng1 is nothing then
set rng = rng1
elseif not rng2 is nothing then
set rng = rng2
Else
set rng = nothing
end if
msgbox rng.Address

--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
I'm trying to use SpecialCells to select all the non-blank cells in my

range.
If my approach is correct please tell me how to complete my code, or

if
there's a better way...

'my approach is to:
set Blanks=MyRange.SpecialCells(xlCellTypeBlanks)
'and then
set MyRange=intersect ( MyRange , [not blanks] )

'but I can't work out how to get [not blanks]

Thanks in advance
Rob








  #6   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Select all cells NOT in a range

ok thanks very much, I'll do it as a seperate function. Sorry to have called
you verbose :-)

"Tom Ogilvy" wrote:

No, you can't union with nothing.

I didn't make it multiline because I like to be verbose - in fact I left out
two critical lines

Dim rng as Range, rng1 as Range, rng2 as Range
Set rng = MyRange
On Error Resume Next
set rng1 = rng.specialcells(xlFormulas)
set rng2 = rng.Specialcells(xlconstants)
On Error goto 0
if not rng1 is nothing and not rng2 is nothing then
set rng = Union(rng1,rng2)
elseif not rng1 is nothing then
set rng = rng1
elseif not rng2 is nothing then
set rng = rng2
Else
set rng = nothing
end if


--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
I'd really like this as a one liner, which would be posible if

specialcells
didn't cause an error. Any ideas?

Union( MyRange.specialcells(xlFormulas) ,

Myrange.SpecialCells(xlconstants) )


"Tom Ogilvy" wrote:

Dim rng as Range, rng1 as Range, rng2 as Range
Set rng = MyRange
set rng1 = rng.specialcells(xlFormulas)
set rng2 = rng.Specialcells(xlconstants)
if not rng1 is nothing and not rng2 is nothing then
set rng = Union(rng1,rng2)
elseif not rng1 is nothing then
set rng = rng1
elseif not rng2 is nothing then
set rng = rng2
Else
set rng = nothing
end if
msgbox rng.Address

--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
I'm trying to use SpecialCells to select all the non-blank cells in my
range.
If my approach is correct please tell me how to complete my code, or

if
there's a better way...

'my approach is to:
set Blanks=MyRange.SpecialCells(xlCellTypeBlanks)
'and then
set MyRange=intersect ( MyRange , [not blanks] )

'but I can't work out how to get [not blanks]

Thanks in advance
Rob






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Select all cells NOT in a range

You didn't call me verbose - that is my term. I don't like having to do it
that way either, but I have never figured out a better way. Someone else
may have a more exciting approach. <g

--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
ok thanks very much, I'll do it as a seperate function. Sorry to have

called
you verbose :-)

"Tom Ogilvy" wrote:

No, you can't union with nothing.

I didn't make it multiline because I like to be verbose - in fact I left

out
two critical lines

Dim rng as Range, rng1 as Range, rng2 as Range
Set rng = MyRange
On Error Resume Next
set rng1 = rng.specialcells(xlFormulas)
set rng2 = rng.Specialcells(xlconstants)
On Error goto 0
if not rng1 is nothing and not rng2 is nothing then
set rng = Union(rng1,rng2)
elseif not rng1 is nothing then
set rng = rng1
elseif not rng2 is nothing then
set rng = rng2
Else
set rng = nothing
end if


--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
I'd really like this as a one liner, which would be posible if

specialcells
didn't cause an error. Any ideas?

Union( MyRange.specialcells(xlFormulas) ,

Myrange.SpecialCells(xlconstants) )


"Tom Ogilvy" wrote:

Dim rng as Range, rng1 as Range, rng2 as Range
Set rng = MyRange
set rng1 = rng.specialcells(xlFormulas)
set rng2 = rng.Specialcells(xlconstants)
if not rng1 is nothing and not rng2 is nothing then
set rng = Union(rng1,rng2)
elseif not rng1 is nothing then
set rng = rng1
elseif not rng2 is nothing then
set rng = rng2
Else
set rng = nothing
end if
msgbox rng.Address

--
Regards,
Tom Ogilvy

"Rob" wrote in message
...
I'm trying to use SpecialCells to select all the non-blank cells

in my
range.
If my approach is correct please tell me how to complete my code,

or
if
there's a better way...

'my approach is to:
set Blanks=MyRange.SpecialCells(xlCellTypeBlanks)
'and then
set MyRange=intersect ( MyRange , [not blanks] )

'but I can't work out how to get [not blanks]

Thanks in advance
Rob








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
Select a range of cells wx4usa Excel Discussion (Misc queries) 2 December 23rd 09 07:32 PM
When entering data into a range of cells, select the entire range. Q Excel Discussion (Misc queries) 0 September 26th 07 04:36 AM
select a range using "cells()" fullers Excel Worksheet Functions 2 July 6th 05 06:00 PM
select from a range only some cells hulub[_4_] Excel Programming 0 September 21st 04 04:29 PM
select from a range only some cells hulub[_3_] Excel Programming 1 September 21st 04 03:14 PM


All times are GMT +1. The time now is 06:31 PM.

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"