Hello,
I tries to run a macro and a message pops up "No cells were found".
The Macro runs fine until the variable dy1 is 5 (Meaning it is day 5 of the month).
Some days are missing as there are weekends were no data are available.
The filter returns nothing (no visible data) as there isn't day 5 in the dataset.
Then the variable visibleTotal cannot be executed. An error pops up: no cells were found.
Can I please get some help?
Sub CountLines()
Dim dy1 As Variant
Dim hour1 As Variant
Dim mth1 As Variant
Dim myRng As Range
Dim Lrow As Long
Dim visibleTotal As Long
'Find the last Row
Lrow = Cells(Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False
For n = 2 To 25 'no of columns for hours
For m = 3 To 33 'rows of days
dy1 = Sheets("Lines").Cells(m, 1).Value
hour1 = Sheets("Lines").Cells(2, n).Value
mth1 = Sheets("Database").Cells(1, 19).Text
Sheets("Database").Select
ActiveSheet.Range("a1:s1").AutoFilter field:=13, Criteria1:=mth1
ActiveSheet.Range("a1:s1").AutoFilter field:=16, Criteria1:=dy1
ActiveSheet.Range("a1:s1").AutoFilter field:=14, Criteria1:=hour1
Cells(2, 17).Select
Set myRng = Cells(2, 17).Resize(Lrow - 1, 1)
visibleTotal = Application.WorksheetFunction.Sum(myRng.SpecialCells(xlCellTypeVisible))
'Paste VisibleTotal in the lines sheet
'Added screenupdating
Application.ScreenUpdating = True
Sheets("Lines").Cells(m, n).Value = visibleTotal
Application.ScreenUpdating = False
'Deactivate AutoFilter
Sheets("Database").Select
ActiveSheet.AutoFilterMode = False
Next 'next row
Next 'next Column
End Sub
I tries to run a macro and a message pops up "No cells were found".
The Macro runs fine until the variable dy1 is 5 (Meaning it is day 5 of the month).
Some days are missing as there are weekends were no data are available.
The filter returns nothing (no visible data) as there isn't day 5 in the dataset.
Then the variable visibleTotal cannot be executed. An error pops up: no cells were found.
Can I please get some help?
Sub CountLines()
Dim dy1 As Variant
Dim hour1 As Variant
Dim mth1 As Variant
Dim myRng As Range
Dim Lrow As Long
Dim visibleTotal As Long
'Find the last Row
Lrow = Cells(Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False
For n = 2 To 25 'no of columns for hours
For m = 3 To 33 'rows of days
dy1 = Sheets("Lines").Cells(m, 1).Value
hour1 = Sheets("Lines").Cells(2, n).Value
mth1 = Sheets("Database").Cells(1, 19).Text
Sheets("Database").Select
ActiveSheet.Range("a1:s1").AutoFilter field:=13, Criteria1:=mth1
ActiveSheet.Range("a1:s1").AutoFilter field:=16, Criteria1:=dy1
ActiveSheet.Range("a1:s1").AutoFilter field:=14, Criteria1:=hour1
Cells(2, 17).Select
Set myRng = Cells(2, 17).Resize(Lrow - 1, 1)
visibleTotal = Application.WorksheetFunction.Sum(myRng.SpecialCells(xlCellTypeVisible))
'Paste VisibleTotal in the lines sheet
'Added screenupdating
Application.ScreenUpdating = True
Sheets("Lines").Cells(m, n).Value = visibleTotal
Application.ScreenUpdating = False
'Deactivate AutoFilter
Sheets("Database").Select
ActiveSheet.AutoFilterMode = False
Next 'next row
Next 'next Column
End Sub