Detecting sheet change, clearing the sheet giving an overflow

前端 未结 1 746
迷失自我
迷失自我 2021-01-23 22:02

I have a Worksheet_Change event, currently at the Sheet Module Level. The problem is that I want to be able to clear this sheet at times. However, when

相关标签:
1条回答
  • 2021-01-23 22:34

    I believe you are using xl2007+?

    The Target.Cells.Count is a Long value and hence when you select the entire worksheet the .Count is too small to hold the result.

    Replace line

    If Target.Count = 1 Then   
    

    with

    If Target.Cells.CountLarge = 1 Then
    

    You might also want to see this since you are using Worksheet_Change

    EDIT:

    Two other things

    1)

    You can also replace this line

    If Target = Range("A4") Then
    

    with

    If Not Intersect(Target, Range("A4")) Is Nothing Then
    

    2)

    This line

    If InStr(LCase(Target.Value), "loaded") <> 0 Then
    

    can also be written as

    If InStr(1, Target.Value, "loaded", vbTextCompare) Then
    
    0 讨论(0)
提交回复
热议问题