Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Intersect or Union?

Maybe:

For Each cell In Sheets(1).UsedRange
If Application.Intersect(cell, Range("I44:N55")) Is Nothing Then
cell.Copy
cell.PasteSpecial xlPasteValues
End If
Next cell

Your idea to deselect an area from the used range will only work if the area
to be excluded from copy/paste is at the edged of the used range because
copy and paste ranges have to be rectangular. Above code will work with any
range.

Cheers,

Joerg Mochikun


"Nigel" wrote in message
...
I have an application that copies the used range on a worksheet and then
pastes values, to remove formula.

I need to deselect a smaller range within the used range before I paste
values, so for the smaller range the formula are retained.

The following replaces all formula, but if I wanted to exclude a smaller
range say ("I44:N55") how could I do this?

With Sheets(1).UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
End With



--

Regards,
Nigel






  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Intersect or Union?

Good point about multiple areas, I didn't even test that far, just that it
got the correct range(s)

--
__________________________________
HTH

Bob

"Joerg Mochikun" wrote in message
...
Maybe:

For Each cell In Sheets(1).UsedRange
If Application.Intersect(cell, Range("I44:N55")) Is Nothing Then
cell.Copy
cell.PasteSpecial xlPasteValues
End If
Next cell

Your idea to deselect an area from the used range will only work if the
area to be excluded from copy/paste is at the edged of the used range
because copy and paste ranges have to be rectangular. Above code will work
with any range.

Cheers,

Joerg Mochikun


"Nigel" wrote in message
...
I have an application that copies the used range on a worksheet and then
pastes values, to remove formula.

I need to deselect a smaller range within the used range before I paste
values, so for the smaller range the formula are retained.

The following replaces all formula, but if I wanted to exclude a smaller
range say ("I44:N55") how could I do this?

With Sheets(1).UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
End With



--

Regards,
Nigel








  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Intersect or Union?

You can use the technique o iterate the ares though rather than all cells

Public Sub Test2()
Dim mpArea As Range
For Each mpArea In AntiUnion(Sheets(1).UsedRange, Range("I44:N55")).Areas
mpArea.Cells.Copy
mpArea.Cells.PasteSpecial xlPasteValues
Next mpArea
End Sub

'-----------------------------------------------------------------
Function AntiUnion(SetRange As Range, UsedRange As Range) As Range
'-----------------------------------------------------------------
Dim saveSet
saveSet = SetRange.Formula
SetRange.ClearContents
UsedRange = 0
Set AntiUnion = SetRange.SpecialCells(xlCellTypeBlanks)
SetRange = saveSet
End Function



--
__________________________________
HTH

Bob

"Bob Phillips" wrote in message
...
Good point about multiple areas, I didn't even test that far, just that it
got the correct range(s)

--
__________________________________
HTH

Bob

"Joerg Mochikun" wrote in message
...
Maybe:

For Each cell In Sheets(1).UsedRange
If Application.Intersect(cell, Range("I44:N55")) Is Nothing Then
cell.Copy
cell.PasteSpecial xlPasteValues
End If
Next cell

Your idea to deselect an area from the used range will only work if the
area to be excluded from copy/paste is at the edged of the used range
because copy and paste ranges have to be rectangular. Above code will
work with any range.

Cheers,

Joerg Mochikun


"Nigel" wrote in message
...
I have an application that copies the used range on a worksheet and then
pastes values, to remove formula.

I need to deselect a smaller range within the used range before I paste
values, so for the smaller range the formula are retained.

The following replaces all formula, but if I wanted to exclude a smaller
range say ("I44:N55") how could I do this?

With Sheets(1).UsedRange
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
End With



--

Regards,
Nigel










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
Complex Union Intersect [email protected] Excel Worksheet Functions 3 May 23rd 07 12:23 PM
Intersect Arne Hegefors Excel Programming 1 July 25th 06 09:38 AM
Equivalent of Minus in Excel. Also Union, Intersect. [email protected] Excel Programming 5 January 30th 06 08:37 PM
Equivalent of Minus in Excel. Also Union, Intersect. KARL DEWEY Excel Worksheet Functions 0 January 27th 06 10:47 PM
Intersect, Union... where's Deduct? rumi Excel Programming 5 September 13th 05 06:39 PM


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