Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Help to modify macro please

I wish to use the following well publicized macro to remove blank rows in a
worksheet.
However I wish to tell it to ignore rows 50 to 55 inclusive.
How would I modify it to achieve this?

Sub DeleteUnused()



Dim myLastRow As Long

Dim myLastCol As Long

Dim wks As Worksheet

Dim dummyRng As Range





For Each wks In ActiveWorkbook.Worksheets

With wks

myLastRow = 0

myLastCol = 0

Set dummyRng = .UsedRange

On Error Resume Next

myLastRow = _

.Cells.Find("*", after:=.Cells(1), _

LookIn:=xlFormulas, lookat:=xlWhole, _

SearchDirection:=xlPrevious, _

SearchOrder:=xlByRows).Row

myLastCol = _

.Cells.Find("*", after:=.Cells(1), _

LookIn:=xlFormulas, lookat:=xlWhole, _

SearchDirection:=xlPrevious, _

SearchOrder:=xlByColumns).Column

On Error GoTo 0



If myLastRow * myLastCol = 0 Then

.Columns.Delete

Else

.Range(.Cells(myLastRow + 1, 1), _

.Cells(.Rows.Count, 1)).EntireRow.Delete

.Range(.Cells(1, myLastCol + 1), _

.Cells(1, .Columns.Count)).EntireColumn.Delete

End If

End With

Next wks


Thanks
Brian Tozer


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Help to modify macro please

One way:

I presume this is just to preserve formatting, right (since there
would be no values to save if myLastRow was < 50)?

Public Sub DeleteUnused()
Dim myLastRow As Long
Dim myLastCol As Long
Dim wks As Worksheet
Dim dummyRng As Range

For Each wks In ActiveWorkbook.Worksheets
With wks
myLastRow = 0
myLastCol = 0
Set dummyRng = .UsedRange
On Error Resume Next
myLastRow = _
.Cells.Find("*", after:=.Cells(1), _
LookIn:=xlFormulas, lookat:=xlWhole, _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
myLastCol = _
.Cells.Find("*", after:=.Cells(1), _
LookIn:=xlFormulas, lookat:=xlWhole, _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column
On Error GoTo 0
If myLastRow * myLastCol = 0 Then
.Columns.Delete
Else
If myLastRow < 55 Then
.Range(.Cells(56, 1), _
.Cells(.Rows.Count, 1)).EntireRow.Delete
If myLastRow < 50 Then _
.Range(.Cells(myLastRow + 1, 1), _
.Cells(49, 1)).EntireRow.Delete
Else
.Range(.Cells(myLastRow + 1, 1), _
.Cells(.Rows.Count, 1)).EntireRow.Delete
End If
.Range(.Cells(1, myLastCol + 1), _
.Cells(1, .Columns.Count)).EntireColumn.Delete
End If
End With
Next wks
End Sub

Note that if the last row is, say 35, that the formatting of rows
50:55 will be in 36:41 after the macro runs.


In article ,
"Brian Tozer" wrote:

I wish to use the following well publicized macro to remove blank rows in a
worksheet.
However I wish to tell it to ignore rows 50 to 55 inclusive.
How would I modify it to achieve this?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Help to modify macro please

J.E. McGimpsey wrote:
One way:


Thanks very much J.E.
Off to clear the log-jam.

Brian Tozer


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
I need to modify my macro ... Dr. Darrell Excel Discussion (Misc queries) 0 February 24th 10 07:21 PM
Modify A Macro carl Excel Worksheet Functions 1 September 27th 07 08:39 PM
Modify a Macro Carl Excel Worksheet Functions 1 October 28th 06 10:32 AM
Modify macro to copy to next available row Liketoknow Excel Discussion (Misc queries) 0 August 23rd 06 10:10 PM
How to modify a copy macro EAHRENS Excel Worksheet Functions 4 March 13th 06 06:58 PM


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