I have following code in excel 2003,to fill blank cell with previous cell value in many worksheets in directory. It work perfectly for one workbook. How to do with many workbook. please help me
Code:
Sub FindFilesn12()
'fill blank
Dim strDocPath As String
Dim strCurrentFile As String
Dim Fname As String
Dim fn As String
Application.ScreenUpdating = False
strDocPath = ThisWorkbook.Path & "\"
strDocPath = "C:\Documents and Settings\Admin\My Documents\eq_der\"
strCurrentFile = Dir(strDocPath & "*.xls")
Do While strCurrentFile <> ""
If strcurerntfile <> ThisWorkbook.Name Then
With Workbooks.Open(strDocPath & strCurrentFile)
With ActiveSheet
col = .Range("a1").Column
Set rng = .UsedRange 'try to reset the lastcell
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set rng = Nothing
On Error Resume Next
Set rng = .Range(.Cells(2, col), .Cells(LastRow, col)) _
.Cells.SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "No blanks found"
Exit Sub
Else
rng.FormulaR1C1 = "=R[-1]C"
End If
'replace formulas with values
With .Cells(1, col).EntireColumn
.Value = .Value
End With
End With
ActiveWorkbook.Save
ActiveWorkbook.Close (False)
End With
End If
strCurrentFile = Dir
Loop
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: