View Single Post
  #8   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

Just an FYI: Your code deletes the range instead of clearing the contents, and only works on the
sheet that is active when the file is opened.

HTH,
Bernie
MS Excel MVP


"Office_Novice" wrote in message
...

Option Explicit
Sub DeleteThatRange()
Dim FolderPath As String
Dim objFSO As Object
Dim objFolder As Object
Dim colFiles As Object
Dim objFile As Variant
Dim msXL As Object
'On Error Resume Next

FolderPath = "C:\Documents and Settings\Desktop\ABC Folder"
Set msXL = CreateObject("Excel.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(FolderPath)
Set colFiles = objFolder.Files



For Each objFile In colFiles
msXL.Visible = True
Workbooks.Open (objFile)
Range("C1:C4").Delete Shift:=xlUp
ActiveWorkbook.Close SaveChanges:=True
Next
End Sub

"Diddy" wrote:

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