Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
it works, it doesn work, its works....and so on. | Excel Programming | |||
web interface for excel | Excel Programming | |||
How do I convert works file to excel without works software? | Excel Discussion (Misc queries) | |||
QUI Expert: Excel-based User Interface or OO User Interface? | Excel Programming | |||
GUI Expert: Excel-based User Interface or OO User Interface? | Excel Programming |