Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Works using XL interface but not in VBA (err: 1004)

Hi everyone. I have an interesting problem.
I created a spreadsheet with groupings on certain rows.
I now want to delete the rows that belong to the grouping through code. To
identify the rows I want to delete I put a dummy comment on one of the cells
in the row and then run the following code to remove the rows:

For each wks in Application.ActiveWorkbook.Worksheets
wks.Activate
ActiveSheet.Cells.SpecialCells(xlCellTypeComments) .EntireRow.Delete
Next

Now it works for some sheets but not others.
I get the error message:
"Cannot use that command on overlapping selections"

Strangely, it works if I perform the steps through the XL interface.
(Edit+Go To+Special...+Comments and then choose Edit+Delete+Entire Row)

Any ideas would be very appreciated.

Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Works using XL interface but not in VBA (err: 1004)

This happens when you have more than one comment on a row. This works
around it:

Sub a()
Dim Area As Range
Dim Rg As Range
For Each Area In Cells.SpecialCells(xlCellTypeComments)
If Rg Is Nothing Then
Set Rg = Area.EntireRow
Else
Set Rg = Union(Rg, Area.EntireRow)
End If
Next
If Not Rg Is Nothing Then Rg.Delete
End Sub


--
Jim
"Jim Bennett" wrote in message
...
| Hi everyone. I have an interesting problem.
| I created a spreadsheet with groupings on certain rows.
| I now want to delete the rows that belong to the grouping through code. To
| identify the rows I want to delete I put a dummy comment on one of the
cells
| in the row and then run the following code to remove the rows:
|
| For each wks in Application.ActiveWorkbook.Worksheets
| wks.Activate
| ActiveSheet.Cells.SpecialCells(xlCellTypeComments) .EntireRow.Delete
| Next
|
| Now it works for some sheets but not others.
| I get the error message:
| "Cannot use that command on overlapping selections"
|
| Strangely, it works if I perform the steps through the XL interface.
| (Edit+Go To+Special...+Comments and then choose Edit+Delete+Entire Row)
|
| Any ideas would be very appreciated.
|
| Thank you.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Works using XL interface but not in VBA (err: 1004)

Hey thanks very much Jim.
I did have multiple comments on the same row and removing them solved the
problem but I will take your code as a better solution.

"Jim Rech" wrote:

This happens when you have more than one comment on a row. This works
around it:

Sub a()
Dim Area As Range
Dim Rg As Range
For Each Area In Cells.SpecialCells(xlCellTypeComments)
If Rg Is Nothing Then
Set Rg = Area.EntireRow
Else
Set Rg = Union(Rg, Area.EntireRow)
End If
Next
If Not Rg Is Nothing Then Rg.Delete
End Sub


--
Jim
"Jim Bennett" wrote in message
...
| Hi everyone. I have an interesting problem.
| I created a spreadsheet with groupings on certain rows.
| I now want to delete the rows that belong to the grouping through code. To
| identify the rows I want to delete I put a dummy comment on one of the
cells
| in the row and then run the following code to remove the rows:
|
| For each wks in Application.ActiveWorkbook.Worksheets
| wks.Activate
| ActiveSheet.Cells.SpecialCells(xlCellTypeComments) .EntireRow.Delete
| Next
|
| Now it works for some sheets but not others.
| I get the error message:
| "Cannot use that command on overlapping selections"
|
| Strangely, it works if I perform the steps through the XL interface.
| (Edit+Go To+Special...+Comments and then choose Edit+Delete+Entire Row)
|
| Any ideas would be very appreciated.
|
| Thank you.



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
it works, it doesn work, its works....and so on. Naz Excel Programming 6 September 30th 05 01:52 PM
web interface for excel Gixxer_J_97[_2_] Excel Programming 0 August 17th 05 11:19 PM
How do I convert works file to excel without works software? CatMB Excel Discussion (Misc queries) 1 June 21st 05 04:12 PM
QUI Expert: Excel-based User Interface or OO User Interface? Michael[_27_] Excel Programming 1 November 11th 04 01:53 PM
GUI Expert: Excel-based User Interface or OO User Interface? Michael[_27_] Excel Programming 0 November 11th 04 01:20 PM


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