Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to combine two SpecialCells CellTypes?


Hi,

I'm looking to create a range that contains all the constant AND
formula cells in a selection. I've tried
'selection.SpecialCells(xlConstants) and
selection.SpecialCells(xlFormulas)' , but that doesn't work because
there may be only one type of cell in the selection - constants or
formulas - and then instead of combining a range with a null set, Excel
throws an error because there are no cells in one of the sets.
It seems there should be an easy way to do this but I haven't found one
online or in any of my books and I'm growing frustrated. Please help if
you have any ideas!

Allison


--
Stacy35216
------------------------------------------------------------------------
Stacy35216's Profile: http://www.excelforum.com/member.php...o&userid=15952
View this thread: http://www.excelforum.com/showthread...hreadid=274326

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default How to combine two SpecialCells CellTypes?

Maybe you can use this

Sub test()
Dim rng As Range
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = Range("A1:C25").SpecialCells(xlConstants)
Set rng2 = Range("A1:C25").SpecialCells(xlFormulas)
Set rng = Application.Union(rng1, rng2)

rng.Select
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Stacy35216" wrote in message ...

Hi,

I'm looking to create a range that contains all the constant AND
formula cells in a selection. I've tried
'selection.SpecialCells(xlConstants) and
selection.SpecialCells(xlFormulas)' , but that doesn't work because
there may be only one type of cell in the selection - constants or
formulas - and then instead of combining a range with a null set, Excel
throws an error because there are no cells in one of the sets.
It seems there should be an easy way to do this but I haven't found one
online or in any of my books and I'm growing frustrated. Please help if
you have any ideas!

Allison


--
Stacy35216
------------------------------------------------------------------------
Stacy35216's Profile: http://www.excelforum.com/member.php...o&userid=15952
View this thread: http://www.excelforum.com/showthread...hreadid=274326



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default How to combine two SpecialCells CellTypes?

Hi Allison,

Try something like:

Sub Tester()
Dim Rng1 As Range
Dim Rng2 As Range
Dim rng3 As Range
Dim mySelection As Range

If Selection.Count = 1 Then
Set mySelection = ActiveSheet.UsedRange
Else
Set mySelection = Selection
End If

On Error Resume Next
Set Rng1 = mySelection.SpecialCells(xlCellTypeConstants)
Set Rng2 = mySelection.SpecialCells(xlCellTypeFormulas)

If Rng1 Is Nothing Then
Set Rng1 = Rng2
ElseIf Rng2 Is Nothing Then
Set Rng2 = Rng1
End If

Err.Clear

On Error Resume Next
Set rng3 = Union(Rng1, Rng2)
If Err.Number < 0 Then
MsgBox "No constants or formulae found!!"
End If

rng3.Select
On Error GoTo 0

End Sub


---
Regards,
Norman



"Stacy35216" wrote in message
...

Hi,

I'm looking to create a range that contains all the constant AND
formula cells in a selection. I've tried
'selection.SpecialCells(xlConstants) and
selection.SpecialCells(xlFormulas)' , but that doesn't work because
there may be only one type of cell in the selection - constants or
formulas - and then instead of combining a range with a null set, Excel
throws an error because there are no cells in one of the sets.
It seems there should be an easy way to do this but I haven't found one
online or in any of my books and I'm growing frustrated. Please help if
you have any ideas!

Allison


--
Stacy35216
------------------------------------------------------------------------
Stacy35216's Profile:
http://www.excelforum.com/member.php...o&userid=15952
View this thread: http://www.excelforum.com/showthread...hreadid=274326



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
Specialcells Bruno Uato Charts and Charting in Excel 0 October 7th 05 07:42 PM
SpecialCells(xlCellTypeLastCell) Tom Ogilvy Excel Programming 0 July 21st 04 03:37 PM
SpecialCells and UsedRange Norm[_5_] Excel Programming 2 April 1st 04 06:53 PM
SpecialCells(xlCellTypeFormulas) Kevin Gabbert Excel Programming 1 January 28th 04 05:06 PM
AutoFilter /specialcells Ron de Bruin Excel Programming 8 January 13th 04 03:45 PM


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