Getting around Overflow (Error 6)

Shanthan

New Member
Joined
Feb 24, 2013
Messages
47
Hi,

I was getting an overflow error at Line 2:

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    If Sheets("User Names").Range("D9").Interior.ColorIndex = xlNone And Selection.Cells.Count = 1 Then
        CurrentCellValue = Target.Value
    End If
End Sub

So, I changed my code to look like this, but I am still getting an overflow error:
Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Dim SelectedCellCount As Long
    SelectedCellCount = Selection.Cells.Count
    
    If Sheets("User Names").Range("D9").Interior.ColorIndex = xlNone And SelectedCellCount = 1 Then
        CurrentCellValue = Target.Value
    End If
End Sub

Does anyone know how to get around this?

Thanks! :biggrin:
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You are using xl2007+ I presume? If you select the entire worksheet cells then the number of cells exceeds the capacity of a Long (which Count returns) so you need to use a different property (CountLarge):

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Target.CountLarge<>1 Then Exit Sub
    If Sheets("User Names").Range("D9").Interior.ColorIndex = xlNone Then
        CurrentCellValue = Target.Value
    End If
End Sub
 
Upvote 0
Thanks so much for the quick reply. I am using Excel 2010, but I need this to work on Excel 2003 as well. Does CountLarge work on Excel 2003?
 
Upvote 0
Hi Andrew,

I am not quite sure what you mean. I was getting the overflow error when I click on the Select All button located left to column A on the column header. Firefly2012's solution works, but I read that CountLarge expression only works in Excel 2007 and up. I was wondering if there is a solution that works on Excel 2003 as well.
 
Upvote 0
Try this instead (for xl2003+ compatibilty):

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If InStr(Target.Address, ":") > 0 Then Exit Sub

    If Sheets("User Names").Range("D9").Interior.ColorIndex = xlNone Then
        CurrentCellValue = Target.Value
    End If
End Sub
 
Upvote 0
Thank you so much, Firefly2012. It works great! If you get a chance, can you please take a look at this link: Resizing comment box I haven't been able to solve this issue.

PS: I wish they hadn't cancelled that show. :biggrin:
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,665
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top