Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Conditional Row Delete on Steriods

I've got 74 Excel files, each with 8 worksheets that I want to delete all
rows where row AA is 0.

The 74 files are located in a path called
"\\oprdgv1\depart\Finance\_Budget\Current Year ePlanning Loads\"

Ideally, it would loop through each file in this path, and delete zero rows
in column AA for each worksheet, then move to the next file and repeat.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Conditional Row Delete on Steriods

AA# has to be 0--not just empty, right?

If all your workbooks to be fixed are in a single folder (and nothing else
there), you could try this macro. But I'd keep a backup someplace else--just in
case!

Option Explicit
Sub testme01()

Dim myNames() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim Wks As Worksheet
Dim TempWkbk As Workbook
Dim iRow As Long
Dim LastRow As Long
Dim FirstRow As Long
Dim myCol As String

Application.ScreenUpdating = False

FirstRow = 1
'check column AA
myCol = "AA"

'change the folder here
myPath = "C:\my documents\excel\test"
If myPath = "" Then Exit Sub
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = ""
On Error Resume Next
myFile = Dir(myPath & "*.xls")
On Error GoTo 0
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile < ""
fCtr = fCtr + 1
ReDim Preserve myNames(1 To fCtr)
myNames(fCtr) = myFile
myFile = Dir()
Loop

If fCtr 0 Then
For fCtr = LBound(myNames) To UBound(myNames)
Application.StatusBar _
= "Processing: " & myNames(fCtr) & " at: " & Now

Set TempWkbk = Workbooks.Open(Filename:=myPath & myNames(fCtr))
For Each Wks In TempWkbk.Worksheets
With Wks
LastRow = .Cells(.Rows.Count, myCol).End(xlUp).Row
For iRow = LastRow To FirstRow Step -1
If IsEmpty(.Cells(iRow, myCol).Value) Then
'skip it
ElseIf .Cells(iRow, myCol).Value = 0 Then
.Rows(iRow).Delete
End If
Next iRow
End With
Next Wks
TempWkbk.Close savechanges:=True
Next fCtr
End If

With Application
.ScreenUpdating = True
.StatusBar = False
End With

End Sub

Kirk P. wrote:

I've got 74 Excel files, each with 8 worksheets that I want to delete all
rows where row AA is 0.

The 74 files are located in a path called
"\\oprdgv1\depart\Finance\_Budget\Current Year ePlanning Loads\"

Ideally, it would loop through each file in this path, and delete zero rows
in column AA for each worksheet, then move to the next file and repeat.


--

Dave Peterson
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
Conditional delete tom[_2_] Excel Discussion (Misc queries) 2 October 15th 09 10:44 PM
Conditional Delete [email protected] New Users to Excel 3 May 25th 07 03:25 AM
Conditional Row Delete [email protected] Excel Programming 7 February 4th 07 06:48 AM
CONDITIONAL DELETE SH Excel Programming 2 August 17th 04 12:01 AM
Conditional row delete Penny[_3_] Excel Programming 1 July 30th 03 06:25 PM


All times are GMT +1. The time now is 10:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"