Hi guys
I need exclude the last row contains positive values for each sheet.
the code will bring all of data based on last row for each sheet , but I want just brings minus values based on lastrow for column E for each sheet
Sub test1()
Dim i%, lrow%, k%, ttl&, tt2&, tt3&
Dim a()
Dim b()
ReDim b(1 To 10000, 1 To 6)
Sheets("BALANCES").[a2:F10000].ClearContents
For i = 1 To Worksheets.Count
With Sheets(i)
If Sheets(i).Name <> "BALANCES" Then 'Loop except balances sheet
lrow = .Cells(Rows.Count, "e").End(xlUp).Row 'Find the last row of the sheets value
a = .Range(.Cells(lrow, "A"), .Cells(lrow, "e")).Value 'Store last row into array
k = k + 1
b(k, 1) = k
b(k, 2) = "OPENING BALANCE " & Date 'Date value
b(k, 3) = Sheets(i).Name
b(k, 4) = a(1, 3)
b(k, 5) = a(1, 4)
b(k, 6) = a(1, 5) '
'Balance Value
ttl = a(1, 3) + ttl
tt2 = a(1, 4) + tt2
tt3 = a(1, 5) + tt3
End If
End With
Next i
With Sheets("BALANCES")
.[a2].Resize(UBound(b, 1), UBound(b, 2)).Value = b 'Call out Array
lrow = .Cells(Rows.Count, "a").End(xlUp).Row + 1
.Cells(lrow, "A").Value = "TOTAL"
.Cells(lrow, "d").Value = ttl
.Cells(lrow, "E").Value = tt2
.Cells(lrow, "F").Value = tt3
End With
End Sub
notice: this file is really simple but my reall data contains at least 30 sheets and about 1000 rows for each sheet
thanks