fill blank cell with previous cell value in many workbook

cds

Board Regular
Joined
Mar 25, 2012
Messages
84
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:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,223,445
Messages
6,172,177
Members
452,446
Latest member
walkman99

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top