Check a range is not the entire sheet?

前端 未结 2 2008
没有蜡笔的小新
没有蜡笔的小新 2020-12-22 01:47

I have this function which is trying to detect when a particular cell value changes. The problem is, if the user selects the whole spreadsheet and presses delete, I get an o

相关标签:
2条回答
  • 2020-12-22 02:14

    Use CountLarge instead of Count

    Private Sub Worksheet_SelectionChange(ByVal target As Range)
        If target.Cells.CountLarge > 1 Then Exit Sub
    
        'Code...
    End Sub
    

    See: MSDN Range.CountLarge Property (Excel)

    0 讨论(0)
  • 2020-12-22 02:18

    I'm assuming you are on Excel 2007+ since the number of rows and columns increased dramatically in those versions. You might have better luck checking to make sure both the row and column count = 1, since those maxes will be much lower than the product of the two (ie, the cell count):

    If Target.Rows.Count = 1 And Target.Columns.Count = 1 Then
    
    0 讨论(0)
提交回复
热议问题