Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default SpecialCells problem

Hi. Just note that it's not just Comments. For example...

Sub Demo()
Debug.Print [A1].SpecialCells(xlFormulas).Count
End Sub

Returns the count of the formulas on the sheet.
--
Dana DeLouis
Windows XP & Office 2003


"Gary''s Student" wrote in message
...
Very good Jim. It works (but I am still puzzled)
--
Gary's Student


"Jim Thomlinson" wrote:

Very interesting... This works (Tested)

Sub ccnt()
Dim rng As Range
Dim rngComments As Range
Dim i As Long

Set rng = Selection
On Error GoTo merr
Set rngComments = Intersect(rng, rng.SpecialCells(xlCellTypeComments))
MsgBox (rngComments.Cells.Count)
Exit Sub

merr:
MsgBox (i & " error")
Exit Sub
End Sub
--
HTH...

Jim Thomlinson


"Gary''s Student" wrote:

Thanks for your effort. Unfortunately your code performs exacltly like
mine.
--
Gary's Student


"Jim Thomlinson" wrote:

That is one of the pitfalls of using Selection is that XL will make a
best
guess for you. Similar to when you highlight a single cell and select
sort.
XL guesses that you are not trying to sort a single cell (there would
be no
point) so it selects the most appropraite area (best guess). Try
using a
range object set to the selection and you should be ok (untested)...

Sub ccnt()
dim rng as range

set rng = selection
i = 0
On Error GoTo merr
i = rng.SpecialCells(xlCellTypeComments).Count
MsgBox (i)
Exit Sub

merr:
MsgBox (i & " error")
Exit Sub
End Sub

--
HTH...

Jim Thomlinson


"Gary''s Student" wrote:

I have been using:

Sub ccnt()
i = 0
On Error GoTo merr
i = Selection.SpecialCells(xlCellTypeComments).Count
MsgBox (i)
Exit Sub

merr:
MsgBox (i & " error")
Exit Sub
End Sub


to count comments in a range. It accurately reports the number of
comments
for all multi-cell ranges.

If, however, I select only a single cell, it reports ALL the
comments on the
worksheet.

Why?
--
Gary's Student



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default SpecialCells problem

Thanks to all of you.

Somehow I erroneously believed that range.SpecialCells() would always be a
proper subset of range. I was right most of the time, wrong in 256 * 65536
cases.
--
Gary's Student


"Tom Ogilvy" wrote:

Pretty Much All special cells functionality is meaningless on an single cell,
so as a convenience, a single cell as the anchor indicates the action should
be taken on the UsedRange. It really isn't more complex than that. This is
consistent both manually and with code.

--
Regards,
Tom Ogilvy


"Dana DeLouis" wrote:

Hi. Just note that it's not just Comments. For example...

Sub Demo()
Debug.Print [A1].SpecialCells(xlFormulas).Count
End Sub

Returns the count of the formulas on the sheet.
--
Dana DeLouis
Windows XP & Office 2003


"Gary''s Student" wrote in message
...
Very good Jim. It works (but I am still puzzled)
--
Gary's Student


"Jim Thomlinson" wrote:

Very interesting... This works (Tested)

Sub ccnt()
Dim rng As Range
Dim rngComments As Range
Dim i As Long

Set rng = Selection
On Error GoTo merr
Set rngComments = Intersect(rng, rng.SpecialCells(xlCellTypeComments))
MsgBox (rngComments.Cells.Count)
Exit Sub

merr:
MsgBox (i & " error")
Exit Sub
End Sub
--
HTH...

Jim Thomlinson


"Gary''s Student" wrote:

Thanks for your effort. Unfortunately your code performs exacltly like
mine.
--
Gary's Student


"Jim Thomlinson" wrote:

That is one of the pitfalls of using Selection is that XL will make a
best
guess for you. Similar to when you highlight a single cell and select
sort.
XL guesses that you are not trying to sort a single cell (there would
be no
point) so it selects the most appropraite area (best guess). Try
using a
range object set to the selection and you should be ok (untested)...

Sub ccnt()
dim rng as range

set rng = selection
i = 0
On Error GoTo merr
i = rng.SpecialCells(xlCellTypeComments).Count
MsgBox (i)
Exit Sub

merr:
MsgBox (i & " error")
Exit Sub
End Sub

--
HTH...

Jim Thomlinson


"Gary''s Student" wrote:

I have been using:

Sub ccnt()
i = 0
On Error GoTo merr
i = Selection.SpecialCells(xlCellTypeComments).Count
MsgBox (i)
Exit Sub

merr:
MsgBox (i & " error")
Exit Sub
End Sub


to count comments in a range. It accurately reports the number of
comments
for all multi-cell ranges.

If, however, I select only a single cell, it reports ALL the
comments on the
worksheet.

Why?
--
Gary's Student




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 Value=0?? Otto Moehrbach Excel Programming 2 December 9th 06 02:23 PM
SpecialCells help Graham Y Excel Programming 2 October 11th 06 05:16 PM
SpecialCells mike Excel Programming 4 June 8th 06 01:50 AM
SpecialCells Peter Excel Programming 3 April 12th 06 02:03 PM
Specialcells Bruno Uato Charts and Charting in Excel 0 October 7th 05 07:42 PM


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