Hi,
I have a folder named "May" with 31 workbooks named (1,2,3,4,....31). Each workbook has a sheet named "SKY".
I need a code to clear contents in cells range (A2: A10 ) of these sheets named "SKY".
Thanks in advance
Need a code
-
- Administrator
- Posts: 78471
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Need a code
Code: Select all
Sub ClearCells()
' Change path as needed; keep the \ at the end
Const strFolder = "C:\Excel\May\"
Dim strFile As String
Dim i As Long
Dim wbk As Workbook
Dim wsh As Worksheet
Application.ScreenUpdating = False
For i = 1 To 31
strFile = i & ".xlsm"
Set wbk = Workbooks.Open(Filename:=strFolder & strFile)
Set wsh = wbk.Worksheets("SKY")
wsh.Range("A2:A10").ClearContents
wbk.Close SaveChanges:=True
Next i
Application.ScreenUpdating = True
End Sub
Best wishes,
Hans
Hans