Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Is there a "Non-Intersect" VBA method to remove a sub-range from a range?

Is there a way to peform the opposite of Intersect - ie remove a range
of cells (such as xlBlanks) from a parent range (such as the
Usedrange)

I've written a UDF below to do this but I'm wondering if there is a
more elegant approach

Regards

Dave


Sub SelectNonBlanks()
UsedRangeAddress(ActiveSheet.Name).Select
End Sub


Function UsedRangeAddress(ws) As Range
Dim myrange1 As Range
Dim myrange2 As Range
Dim myrange3 As Range
On Error GoTo error1
Set myrange1 = Intersect(Sheets(ws).UsedRange,
Sheets(ws).Cells.SpecialCells(xlFormulas))
On Error GoTo 0
On Error GoTo error2
Set myrange2 = Intersect(Sheets(ws).UsedRange,
Sheets(ws).Cells.SpecialCells(xlConstants))
On Error GoTo 0

If Not myrange1 Is Nothing And Not myrange2 Is Nothing Then
Set myrange3 = Union(myrange1, myrange2)
ElseIf Not myrange1 Is Nothing Then
Set myrange3 = myrange1
ElseIf Not myrange2 Is Nothing Then
Set myrange3 = myrange2
End If
Set UsedRangeAddress = myrange3
Exit Function
error1:
'no formulas
Set myrange1 = Nothing
Resume Next
error2:
'no constants
Set myrange2 = Nothing
Resume Next
End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Is there a "Non-Intersect" VBA method to remove a sub-range from a range?

Hi brettdj,

Here is Housaka's tips.
http://homepage2.nifty.com/housaka/excel/ununion.txt

Sub UnselectSelectedRange() may make sense.


---
Message posted from http://www.ExcelForum.com/

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 method of Range class failed" Error Ayo Excel Discussion (Misc queries) 3 September 2nd 08 07:58 PM
Run-time error "1004" Select method of range class failed Tallan Excel Discussion (Misc queries) 3 March 7th 07 05:22 PM
Array as a "named range" - formula ok in cells, but error as "named range" tskogstrom Excel Discussion (Misc queries) 11 December 28th 06 04:44 PM
"Run-time error '1004'" Method 'Range' of object '_global' failed. haisat[_2_] Excel Programming 0 October 20th 03 12:13 PM


All times are GMT +1. The time now is 05:42 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"