Clarify question "Process Workbook"

G

Guest

I have 12 worksheets in a workbook. Column K has a Date field.
The rows may vary from sheet to sheet. I need to delete any rows
that have a Date less than "todays" date .
I need to loop through all 12 worksheets.
I need to update the code I have. Thank you.

Sub ProcessWorkbook()
Dim bk As Workbook, sh As Worksheet
Dim rng As Range, lastrow As Long
Set bk = Workbooks.Open("N:\ClinicTECList.xls")
For Each sh In bk.Worksheets
lastrow = sh.Cells(Rows.Count, 4).End(xlUp) .Row
For i = lastrow To 1 Step -1
Set rng = sh.Cells(i, 4)
If Not IsEmpty(rng) Then
If IsDate(rng) Then
If rng < Date Then
rng.EntireRow.Delete
End If
End If
End If
Next
Next
End Sub
 
D

David Lloyd

One observation is that you are referring to the fourth column (Column D) in
the line:

Set rng = sh.Cells(i, 4)

Column K is column 11.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I have 12 worksheets in a workbook. Column K has a Date field.
The rows may vary from sheet to sheet. I need to delete any rows
that have a Date less than "todays" date .
I need to loop through all 12 worksheets.
I need to update the code I have. Thank you.

Sub ProcessWorkbook()
Dim bk As Workbook, sh As Worksheet
Dim rng As Range, lastrow As Long
Set bk = Workbooks.Open("N:\ClinicTECList.xls")
For Each sh In bk.Worksheets
lastrow = sh.Cells(Rows.Count, 4).End(xlUp) .Row
For i = lastrow To 1 Step -1
Set rng = sh.Cells(i, 4)
If Not IsEmpty(rng) Then
If IsDate(rng) Then
If rng < Date Then
rng.EntireRow.Delete
End If
End If
End If
Next
Next
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