Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Delete a selected area from a non-contiguous range

Hi all

I have a named range ("List") that is a non-contiguous range, eg A1,
A3, A5

If the last cell has a certain value I wish to redefine the range to
exclude that cell (ie, A1, A3)

What's the best way to do this?

Regards

Paul Martin
Melbourne, Australia

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Delete a selected area from a non-contiguous range

Hi all

This may not be the best way, but it works, because I am able to delete
the unwanted value:

Dim rngList As Range

Set rngList = Range("List").SpecialCells(xlCellTypeConstants)

With rngList
If .Areas(.Areas.Count).Value = "SomeValue" Then
.Areas(.Areas.Count).ClearContents
End If
End With

Set rngList = Range("List").SpecialCells(xlCellTypeConstants)


Paul Martin
Melbourne, Australia

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Delete a selected area from a non-contiguous range

On 9/1 I posted a question as to remove a subrange from a range ( basically
to un-do an UNION). Tom Ogilvy posted the following macro:

Function Disunion(rng As Range, NewStuff As Range) As Range
Dim rng1 As Range, cell As Range
For Each cell In rng
If Intersect(cell, NewStuff) Is Nothing Then
If rng1 Is Nothing Then
Set rng1 = cell
Else
Set rng1 = Union(cell, rng1)
End If
End If
Next
Set Disunion = rng1
End Function

This re-builds the range cell-by-cell, excluding the un-wanted part.
Perhaps this can help you.
--
Gary''s Student


"Paul Martin" wrote:

Hi all

This may not be the best way, but it works, because I am able to delete
the unwanted value:

Dim rngList As Range

Set rngList = Range("List").SpecialCells(xlCellTypeConstants)

With rngList
If .Areas(.Areas.Count).Value = "SomeValue" Then
.Areas(.Areas.Count).ClearContents
End If
End With

Set rngList = Range("List").SpecialCells(xlCellTypeConstants)


Paul Martin
Melbourne, Australia


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Delete a selected area from a non-contiguous range

I've seen Tom's code previously, and it would work in this case, but not
as efficiently as how I am doing it now. Thanks all the same.

Regards

Paul Martin
Melbourne, Australia

*** Sent via Developersdex http://www.developersdex.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
How to repeat a code for selected sheets (or a contiguous range of sheets) in a Workbook? Dmitry Excel Worksheet Functions 6 March 29th 06 12:43 PM
trying to delete selected range with macro DKY[_74_] Excel Programming 7 August 27th 05 01:58 PM
delete every nth row in selected range cwinters Excel Discussion (Misc queries) 1 July 6th 05 08:17 PM
delete row if no data, non-contiguous range problem rjamison Excel Programming 0 June 14th 05 12:14 AM
delete row if no data, non-contiguous range problem Nile Gilmanov Excel Programming 12 April 23rd 05 12:36 PM


All times are GMT +1. The time now is 10:18 AM.

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

About Us

"It's about Microsoft Excel"