Delete Row Sub not working

G

Guest

I have a delete row routine which works. Its the First Macro below. I am
trying to make it more modular by making the delete routine a sub that is
called. This is called Second macro below. However its not working. Not
sure if its the way I have dimenionsed my variable A in the second macro or
if its the way I am passing it to the sub.

First Macro
Sub MemoryManager()
Dim UsedRows As Double
Dim LastRow As Double
Dim RowCounter As Double

UsedRows = 5
LastRow = 20

Range(Range("FirstCell").Offset(UsedRows, 0),
Range("FirstCell").Offset(LastRow, 0)).EntireRow.Clear

End Sub

Second Macro
Sub MemoryManager()
Dim UsedRows As Double
Dim LastRow As Double
Dim RowCounter As Double
Dim A As Object

UsedRows = 5
LastRow = 20

Set A = Range("FirstCell")

Call DeleteUnusedRows(A, UsedRows, LastRow)

End Sub

Sub DeleteUnusedRows(X As Range, Y As Double, Z As Double)

Range(Range(X).Offset(Y, 0), Range(X).Offset(Z, 0)).EntireRow.Delete

End Sub

Thanks

EM
 
G

Guest

Second Macro
Sub MemoryManager()
Dim UsedRows As Double
Dim LastRow As Double
Dim RowCounter As Double
Dim A As Range '<==

UsedRows = 5
LastRow = 20

Set A = Range("FirstCell")

Call DeleteUnusedRows(A, UsedRows, LastRow)

End Sub

Sub DeleteUnusedRows(X As Range, Y As Double, Z As Double)

x.parent.Range(X.Offset(Y, 0), X.Offset(Z, 0)).EntireRow.Delete '<==

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top