Hello all, the algorithm below is meant to open every xls file in a folder then calculate a sum but each workbook have a different number of rows. Im trying to write the sum command with a variable 'ru' to accomodate for this but no success so far. Here's the macro I have, can someone have a quick look and point out my error please?
Any help is really appreciated
Lovi
Any help is really appreciated
Lovi
Code:
Option Explicit
Sub Open_All_Files()
Dim oWbk As Workbook
Dim sFil As String
Dim sPath As String
Dim lr As Long
Dim ru As Integer
sPath = "C:\New folder"
ChDir sPath
sFil = Dir("*.xls")
Do While sFil <> ""
Set oWbk = Workbooks.Open(sPath & "\" & sFil)
lr = Cells(Rows.Count, "H").End(xlUp).Row
ru = lr - 5
ActiveSheet.Range("N5").Value = ru
ActiveSheet.Range("N6") = "=SUM(R[5]C[-2]:R[ru]C[-2])"
oWbk.Close True
sFil = Dir
Loop
End Sub
Last edited: