View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Clear 4 cells in every file in folder

Sub LoopThroughFilesExample()
Application.DisplayAlerts = False

'Change this to your directory
myPath = "C:\Documents and Settings\UserName\My Documents\Excel\"
WorkFile = Dir(myPath & "*.xls")
Do While WorkFile < ""

Application.StatusBar = "Now working on " & WorkFile

Workbooks.Open FileName:=myPath & WorkFile
'Here is the line that calls the macro below, passing the workbook to it
DoSomething ActiveWorkbook
ActiveWorkbook.Save
ActiveWorkbook.Close
WorkFile = Dir()
Loop

Application.StatusBar = False

End Sub

Sub DoSomething(inBook As Workbook)
Dim wkSht As Worksheet
For Each wkSht In inBook.Worksheets
'Do whatever you want here to each worksheet....
wkSht.Range("C1:C4").ClearContents
Next wkSht
End Sub


--
HTH,
Bernie
MS Excel MVP


"Diddy" wrote in message
...
Hi everyone,

I wonder if anyone could help me with this please?

I would like to clear the contents of cells C1-C4 in all the sheets in all
the files in one folder.

I'm only just getting to grips with looping through and just can't work this
out.

Many thanks
--
Deirdre