#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Loop until

THANKS TO GARY BROWN for this awesome macro.
This is working but seems to need to be repeated to ensure that all hidden
rows are being deleted. Just one more tweek and it will be perfect.
How/where would you put a loop reference for just the Row (myrange)
subroutine?

'/======================================/
Public Sub FindHiddenAndLock()
Dim mCell As Range, MyRange As Range
Dim MyColumns As Range

On Error GoTo exit_Sub

Set MyRange = Range("A1:A20")
Set MyColumns = Range("A:E")

---------THIS IS THE ROW SUBROUTINE---------------------
For Each mCell In MyRange
If mCell.Rows.Hidden = True Then
Application.DisplayAlerts = False
mCell.EntireRow.Delete
Application.DisplayAlerts = True
End If
Next mCell

For Each mCell In MyColumns
If mCell.Columns.Hidden = True Then
Application.DisplayAlerts = False
mCell.EntireColumn.Delete
Application.DisplayAlerts = True
End If
Next mCell

exit_Sub:
On Error Resume Next
Application.DisplayAlerts = True
Set MyColumns = Nothing
Set MyRange = Nothing
Exit Sub

End Sub
'/======================================/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Loop until

Sub ABC()
Dim i as Long
for i = 20 to 1 step -1
if rows(i).Hidden then rows(i).Delete
Next
for i = 5 to 1 step -1
if columns(i).Hidden then columns(i).Delete
Next
End Sub


--
Regards,
Tom Ogilvy

"ttbbgg" wrote in message
...
THANKS TO GARY BROWN for this awesome macro.
This is working but seems to need to be repeated to ensure that all hidden
rows are being deleted. Just one more tweek and it will be perfect.
How/where would you put a loop reference for just the Row (myrange)
subroutine?

'/======================================/
Public Sub FindHiddenAndLock()
Dim mCell As Range, MyRange As Range
Dim MyColumns As Range

On Error GoTo exit_Sub

Set MyRange = Range("A1:A20")
Set MyColumns = Range("A:E")

---------THIS IS THE ROW SUBROUTINE---------------------
For Each mCell In MyRange
If mCell.Rows.Hidden = True Then
Application.DisplayAlerts = False
mCell.EntireRow.Delete
Application.DisplayAlerts = True
End If
Next mCell

For Each mCell In MyColumns
If mCell.Columns.Hidden = True Then
Application.DisplayAlerts = False
mCell.EntireColumn.Delete
Application.DisplayAlerts = True
End If
Next mCell

exit_Sub:
On Error Resume Next
Application.DisplayAlerts = True
Set MyColumns = Nothing
Set MyRange = Nothing
Exit Sub

End Sub
'/======================================/



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
For Each ... Next loop - need to reference the loop variable [email protected] Excel Programming 4 July 13th 06 06:12 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Loop Function unable to loop Junior728 Excel Programming 1 July 28th 05 10:23 AM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


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