Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA Range.Cells.Count limitation 1

Status
Not open for further replies.

combo

Technical User
Jan 1, 2003
4,176
PL
Some worksheet events expose [tt]Target As Range[/tt] argument to check processed range before executing the rest of code. In one of my old workbooks I had, to first check if one or more cells were selected:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
[pre]If Target.Cells.Count = 1 Then
...
End If
End Sub[/pre]

By accident I right-clicked 'Select all' button, and got 'overflow' runtime error in reply. Cells.Count returns Long value, with upper limit below worksheet size.
[tt]Target.Cells.CountLarge[/tt] removes this error. CountLarge returns Variant type value. What was strange for me, in Excel 2016, 32 bit, Locals window, I can see proper number of cells (17179869184) with type Variant/<Unsupported variant type>.


combo
 
combo,

Thanks for the Tip.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top