score:4
the error is on 362 * 100
. it is considered integer
and it is up to 32767
.
try like this:
public sub testme()
dim pct as double
pct = (cdbl(362) * 100) / 2005
end sub
the problem is that if you have any of the following 4 mathematic expressions (+-/*
) with values under 2^15-1
or 32767
, vba considers them integer
and the result is tried to be parsed to integer
as well. (the integer
values are actually from -32768
to 32767
)
thus, 32767+1
gives an overthrow error. if you try with 32768+1
it will be ok, because 32768
will be parsed to long
.
for the power operator, ^
, vba parses to double
and it is quite ok - 2 ^ 10 + 32000
score:3
because the integer
type in vba is 16 bits signed, and 36200 overflows its maximum value of 32767. you can avoid this by appending &
to one of the operands to make it a long
literal, for example (362& * 100) / 2005
.
Source: stackoverflow.com
Related Query
- Excel VBA throws overflow error with a simple division
- Overflow Error in Excel VBA with Type Double
- Overflow Error 6 with the following Excel 2010 VBA
- Excel VBA Overflow Error with Dynamic Array
- Getting Run-Time error 6: Overflow in very simple Excel VBA code (Mac)
- Excel VBA Overflow error when trying to run SQL server stored proc with Int parameter
- Excel VBA out of memory error with simple line of code
- Adding comment with Excel VBA throws Application-defined or operation-defined error
- Getting overflow error for double variable with one decimal in Excel VBA
- Error in finding last used cell in Excel with VBA
- simple vba code gives me run time error 91 object variable or with block not set
- VBA Excel simple Error Handling
- VBA for Excel throws "Object variable or with block variable not set" when there is no Object
- Excel is calculating a formula with a VBA function as an error unless it is re-entered
- How do i determine if an error is in any cell in the entire workbook with Excel VBA
- Error 462: The remote server machine does not exist when working with Word via Excel VBA
- Error with copy/paste in excel 2010 VBA when trying to insert charts, ranges etc into word
- Excel 2010 VBA Error 1004 with formula
- Automation Error Unspecified Error with Internet Explorer Object Excel VBA
- Type mismatch error when creating a pivot table in Excel with VBA
- Excel 2010 VBA - error : Object variable or With Block variable not set
- Formula with quotes into cell using VBA throws error
- Overflow error with Mod in VBA when value is in the billions or greater
- Excel VBA runtime error 1004 only with names that begin with 'c'
- Excel VBA For Loop Not Working, Keeps coming up with error message
- VBA Excel - overflow error on range select
- #VALUE error with Excel VBA Function
- excel VBA formula throws #name error
- Excel VBA code throws run-time error 429 while sending Outlook email using Task Scheduler
- Excel vba simple textbox insert sub error
More Query from same tag
- How to delete duplicates in excel in different situations (VBA)?
- Run Access queries with VBA from c#
- Hierarchical Representation using outline grouping in Excel
- Copy method fail due to memory
- Macro for filling-out forms in Google Drive does not send any information
- Passing parameters from Outlook to Excel
- Timeline Slicer Excel 2013 VBA
- Conditional insert of page breaks
- OTA version 12.21 and ALM version 11.52 compatibility issue
- Sum of Named Ranges to Array in Excel
- VBA Offset acting strange?
- Searching a word + autofilter
- Excel VBA variable variable names
- Searching a column for a string and printing results in successive rows
- Change font in a cell based on a value
- Check if email address contains not allowed characters
- How can I find out if a cell in Excel contains a number/text or a formula?
- Trying to convert an Excel Macro over to standalone VBScript
- Is there a way to verify if the User's time and date is correct in microsoft access vba?
- VBA - Print lines to a .txt file
- Row processing taking too long
- Insert line break before a specific word vba
- VBA: Loop for string
- Performance issues when copying the first N columns of table A to table B using Excel VBA
- Passing an Empty/Null Date variable in VBA to an SQL UPDATE statement
- Creating event for Word
- Excel SUMIFS Multiple Criteria Cell Value
- Is empty is not working
- How can Form's length be extended?
- Copy data and re-order columns and paste in to another workbook