+ Reply to Thread
Results 1 to 5 of 5

Overflow error on worksheet_selectionchange when counting selected cells

Hybrid View

Spritz Overflow error on... 06-05-2014, 04:44 PM
LJMetzger Re: Overflow error on... 06-05-2014, 05:38 PM
Spritz Re: Overflow error on... 06-06-2014, 10:19 AM
asraf2asif Re: Overflow error on... 11-04-2021, 02:56 AM
LJMetzger Re: Overflow error on... 11-04-2021, 01:05 PM
  1. #1
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Overflow error on worksheet_selectionchange when counting selected cells

    Hi Spritz,

    I couldn't duplicate your error probably because I am using Excel 2003. When I selected top left, the count was 16,777,216. Yours is going to be a lot larger using Excel 2010 which may overflow the long integer variable type.

    Try one of the following:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
      Dim iCellCount As Long
      
      On Error Resume Next
      iCellCount = Target.Cells.Count
      On Error GoTo 0
    
      If iCellCount = 5 And Not Intersect(Target, Range("W5")) Is Nothing Then
        Call frmcalendar.displayin(Range("W5"))
      End If
      
    End Sub
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
      Dim iCellCount As Long
      
      On Error Resume Next
      iCellCount = Target.Cells.Count
      If Err.Number <> 0 Then
        On Error GoTo 0
        Exit Sub
      End If
      On Error GoTo 0
    
      If iCellCount = 5 And Not Intersect(Target, Range("W5")) Is Nothing Then
        Call frmcalendar.displayin(Range("W5"))
      End If
      
    End Sub
    Lewis

  2. #2
    Registered User
    Join Date
    02-21-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Office 2010
    Posts
    96

    Re: Overflow error on worksheet_selectionchange when counting selected cells

    Worked Great thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] inserting cells when conditions not met, overflow error
    By vcorby in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-13-2012, 01:10 PM
  2. Explanation of the Run-time error '6': Overflow Error
    By mgphill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-25-2012, 10:46 AM
  3. Want to do a while-loop but get error message: run error '6' overflow
    By danzi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2011, 01:48 PM
  4. Overflow error copying cells?
    By AussieM8 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-04-2010, 11:10 AM
  5. Worksheet_SelectionChange get shape in the selected cell
    By FaithRaven in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-11-2009, 09:56 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1