+ Reply to Thread
Results 1 to 5 of 5

Overflow error on worksheet_selectionchange when counting selected cells

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

    Overflow error on worksheet_selectionchange when counting selected cells

    Hi,

    What I want to do is pretty simple. I have a sheet where I have a calendar form called when the user selects a specific cell. Now this cell is merged together with 4 other cells for a total of 5 cells. I know how everyone feels about merged cells but given the way my sheet is laid out it was unavoidable. Basically it is a time entry sheet. So I have a worksheet_selectionchange event that calls the calendar when you select the cell. This code is fairly simple.

    Please Login or Register  to view this content.
    This code works as expected and will only call upon the calendar if W5 is selected. The issue I have now is that if i were to select all cells (top left corner box) I get a run-time error 6 - Overflow on the line:

    Please Login or Register  to view this content.
    I have also tried using the following code:

    Please Login or Register  to view this content.
    And again i get the same error on the top line where it says target.cells.count = 5

    I have code that copies the entire sheet over by selecting the top left corner box which is why i need this fixed otherwise i wouldnt care

    Any help on this is appreciated.

    Thanks!
    Last edited by Spritz; 06-05-2014 at 04:50 PM.

  2. #2
    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:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Lewis

  3. #3
    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!

  4. #4
    Registered User
    Join Date
    11-04-2021
    Location
    Bangladesh
    MS-Off Ver
    2007
    Posts
    1

    Re: Overflow error on worksheet_selectionchange when counting selected cells

    It Worked in my case also, thanks!

  5. #5
    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

    Sometime in the Past Excel 2007 added CountLarge which DOES NOT generate an Overflow error

    Reference: https://docs.microsoft.com/en-us/off...nge.countlarge

    The following code demonstrates.
    NOTE: .Count will generate a 'runtime error 6 - overflow' when you select the entire page

    Please Login or Register  to view this content.
    Lewis

+ 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