I'm new to vba. I have a shared workbook with VBA macros. The first execution of the code works in a timely manner, however, subsequent executions takes minutes to complete (if it even completes). I have been removing code little by little to find the culprit. A snippet is below.
The range clear line appears to cause the problems. If it is removed, my stripped down code works instantaneously. If added, the code hangs.
Also, as an added twist, if the workbook is unshared, the code works fine with and without the range clear.
Any clues would be greatly appreciated. I have not found anything particular about clearing cells with shared workbooks. I'm at a loss.
Code:
daysAhead = InputBox("Input desired # of calendar days:")
testDate = Date + daysAhead
With Sheets(SheetToUse)
.Activate
.AutoFilterMode = False
End With
lrow = Application.Match("PROJECTS", Range("E:E"), 0)
If IsError(lrow) = True Then
MsgBox "Invalid Worksheet: " & SheetToUse
Exit Sub
End If
Set rng1 = RealUsedRange(SheetToUse) 'found this function by Googling
Range(Cells(1, 1), Cells(lrow - 3, rng1.Columns.Count)).Clear
The range clear line appears to cause the problems. If it is removed, my stripped down code works instantaneously. If added, the code hangs.
Also, as an added twist, if the workbook is unshared, the code works fine with and without the range clear.
Any clues would be greatly appreciated. I have not found anything particular about clearing cells with shared workbooks. I'm at a loss.