Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
"Select method of Range class failed" Error | Excel Discussion (Misc queries) | |||
Run-time error "1004" Select method of range class failed | Excel Discussion (Misc queries) | |||
Array as a "named range" - formula ok in cells, but error as "named range" | Excel Discussion (Misc queries) | |||
"Run-time error '1004'" Method 'Range' of object '_global' failed. | Excel Programming |