Darren_workforce
Board Regular
- Joined
- Oct 13, 2022
- Messages
- 146
- Office Version
- 365
- Platform
- Windows
Hello,
I have a large amount of code but the only part I am having issues with is below. Each day's data varies on length so if we have 15 agents versus 30, the number of rows will change. But there will never be 99 agents so I just used that to cover any particular day. On the last line, though, there is always going to be an average line that averages out every column from D:Q. When the cells are being cleared, if all values for a certain metric are zero, the average cell populates a #DIV/0 error. This seems to be what's causing the code to get hung up.
When I go into debug and then delete the cells with the DIV/0 error and then Step Out to run the rest of the macro, it works. So it has to be the error, right?
Is there a way to add a line so that the ClearContents request ignores the errors?
I have a large amount of code but the only part I am having issues with is below. Each day's data varies on length so if we have 15 agents versus 30, the number of rows will change. But there will never be 99 agents so I just used that to cover any particular day. On the last line, though, there is always going to be an average line that averages out every column from D:Q. When the cells are being cleared, if all values for a certain metric are zero, the average cell populates a #DIV/0 error. This seems to be what's causing the code to get hung up.
When I go into debug and then delete the cells with the DIV/0 error and then Step Out to run the rest of the macro, it works. So it has to be the error, right?
Is there a way to add a line so that the ClearContents request ignores the errors?
VBA Code:
Dim cell, rng As Range
Set rng = Range("D2:Q99")
For Each cell In rng
If cell.Value = "0" Then
cell.ClearContents
Else
End If
Next cell