Dividing variables

  • Thread starter Thread starter Merlynsdad
  • Start date Start date
M

Merlynsdad

I need to divide two variables by each other to get a percentage.

intRows represents the total rows in the spreadsheet.
intPerf represents the rows left after I remove some rows with code.
intPct = intPerf/intRows.

All are dimensioned as integers.

When I do the calculation the value in the Watch List of intRows is 88,
intPerf is 34. intPct should then be 38.63% but is showing zero. The code for
the division is

intPct=intPerf/intRows

What am I doing wrong?
 
Merlynsdad,

An integer variable takes an integer value. Since .3863 is not an integer
value, VBA will return the next best value which will satisfy an integer
(i.e. 0 in your case). Change intPct to be a different data type, say a
Double or a Single.

Dim dblPct As Double
dblPct = intPerf/intRows

Best,

Matthew Herbert
 
If you are dimesioning you variable intPct as an integer, you will get a 0
value. The intPct should be dimensioned as a double to get the decimal
value of a percent.

Dim intPct As Double
 
Back
Top