Hello;
I have some embedded VBA I'm using that clears the contents of a cell if another cell is changed. These columns are used for data trending, and so its basically to ensure the data is trending correctly (i.e. sub-area matches area)
Here is the code:
The issue I have is this code is embedded in a large excel file that is shared between multiple (up to 10) users, all working and editing off the same or different sheets at the same time. I know sharing causes its own host of issues, and every now and then the code "falls over" and the ClearContents command fails with a run-time error with some crazy number and the text "Method 'ClearContents' of object 'Range' failed"
This is a big pain because when it happens the macro gets stuck in a loop. Because the file is shared, VBA is not accessible to break, meaning the user has to force out of excel.
My question is two-pronged:
Is there anything that can actually stop this error from happening? I believe its related to the funkiness of shared files and having multiple changes happen back to back from different people (I can only make it "fall over" by myself if making a lot of changes very fast).
If I can't do anything to help this error, is there something I can do so it skips over the error so users don't have to force out of the file? Its fine if the VBA doesn't run that one time and the cell doesn't clear. I'll take 99% accuracy over users being aggravated having to force out of excel.
I have some embedded VBA I'm using that clears the contents of a cell if another cell is changed. These columns are used for data trending, and so its basically to ensure the data is trending correctly (i.e. sub-area matches area)
Here is the code:
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("M:M")) Is Nothing Then
ActiveCell.Offset(0, 1).ClearContents
End If
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("O:O")) Is Nothing Then
ActiveCell.Offset(0, 1).ClearContents
End If
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("Q:Q")) Is Nothing Then
ActiveCell.Offset(0, 1).ClearContents
End If
End Sub
The issue I have is this code is embedded in a large excel file that is shared between multiple (up to 10) users, all working and editing off the same or different sheets at the same time. I know sharing causes its own host of issues, and every now and then the code "falls over" and the ClearContents command fails with a run-time error with some crazy number and the text "Method 'ClearContents' of object 'Range' failed"
This is a big pain because when it happens the macro gets stuck in a loop. Because the file is shared, VBA is not accessible to break, meaning the user has to force out of excel.
My question is two-pronged:
Is there anything that can actually stop this error from happening? I believe its related to the funkiness of shared files and having multiple changes happen back to back from different people (I can only make it "fall over" by myself if making a lot of changes very fast).
If I can't do anything to help this error, is there something I can do so it skips over the error so users don't have to force out of the file? Its fine if the VBA doesn't run that one time and the cell doesn't clear. I'll take 99% accuracy over users being aggravated having to force out of excel.
Last edited: