Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hello, I have a function that scans a data set looking for the row index where two consecutive values in the specified column have a % difference of 40%. It recently came to my attention that Excel was rounding the cell values to the nearest whole integer. This should not occur, since I have declared the variables as Longs. Here is the code: Dim i As Integer Dim j As Integer Dim data1 As Long Dim data2 As Long Do While i <= (lastrow - 1) And flag3_1 = 0 data1 = outputPage.Cells(i, 13).Value data2 = outputPage.Cells(i - 1, 13).Value If Abs((data1 - data2) / data1) = 0.4 Then[/b] Location3_1 = i X3_1Start = Location3_1 - 10 X3_1End = Location3_1 + 49 flag3_1 = 1 Else: i = i + 1 End If Loop ******************* data1 is read in as 0 when the actual value is 0.258558005094528. data2 is read in as 1 when the actual value is 0.778554022312164. How can I keep this from happening so I don't receive anymore division by 0 errors?? Thanks! -- 3PhaseMacroMan ------------------------------------------------------------------------ 3PhaseMacroMan's Profile: http://www.excelforum.com/member.php...o&userid=29945 View this thread: http://www.excelforum.com/showthread...hreadid=502529 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Longs are Long Integers, so they would. Type the variables as Double.
-- HTH Bob Phillips (remove nothere from email address if mailing direct) "3PhaseMacroMan" <3PhaseMacroMan.21ubeq_1137604208.4059@excelforu m-nospam.com wrote in message news:3PhaseMacroMan.21ubeq_1137604208.4059@excelfo rum-nospam.com... Hello, I have a function that scans a data set looking for the row index where two consecutive values in the specified column have a % difference of 40%. It recently came to my attention that Excel was rounding the cell values to the nearest whole integer. This should not occur, since I have declared the variables as Longs. Here is the code: Dim i As Integer Dim j As Integer Dim data1 As Long Dim data2 As Long Do While i <= (lastrow - 1) And flag3_1 = 0 data1 = outputPage.Cells(i, 13).Value data2 = outputPage.Cells(i - 1, 13).Value If Abs((data1 - data2) / data1) = 0.4 Then[/b] Location3_1 = i X3_1Start = Location3_1 - 10 X3_1End = Location3_1 + 49 flag3_1 = 1 Else: i = i + 1 End If Loop ******************* data1 is read in as 0 when the actual value is 0.258558005094528. data2 is read in as 1 when the actual value is 0.778554022312164. How can I keep this from happening so I don't receive anymore division by 0 errors?? Thanks! -- 3PhaseMacroMan ------------------------------------------------------------------------ 3PhaseMacroMan's Profile: http://www.excelforum.com/member.php...o&userid=29945 View this thread: http://www.excelforum.com/showthread...hreadid=502529 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
Long is an INTEGER declaration - change data1/2 to DOUBLE "3PhaseMacroMan" wrote: Hello, I have a function that scans a data set looking for the row index where two consecutive values in the specified column have a % difference of 40%. It recently came to my attention that Excel was rounding the cell values to the nearest whole integer. This should not occur, since I have declared the variables as Longs. Here is the code: Dim i As Integer Dim j As Integer Dim data1 As Long Dim data2 As Long Do While i <= (lastrow - 1) And flag3_1 = 0 data1 = outputPage.Cells(i, 13).Value data2 = outputPage.Cells(i - 1, 13).Value If Abs((data1 - data2) / data1) = 0.4 Then[/b] Location3_1 = i X3_1Start = Location3_1 - 10 X3_1End = Location3_1 + 49 flag3_1 = 1 Else: i = i + 1 End If Loop ******************* data1 is read in as 0 when the actual value is 0.258558005094528. data2 is read in as 1 when the actual value is 0.778554022312164. How can I keep this from happening so I don't receive anymore division by 0 errors?? Thanks! -- 3PhaseMacroMan ------------------------------------------------------------------------ 3PhaseMacroMan's Profile: http://www.excelforum.com/member.php...o&userid=29945 View this thread: http://www.excelforum.com/showthread...hreadid=502529 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
IF FUNCTION NOT WORKING PROPERLY | Excel Discussion (Misc queries) | |||
SUMIF function being used properly? | Excel Worksheet Functions | |||
my sum function is not working properly | Excel Discussion (Misc queries) | |||
function does not work properly | Excel Worksheet Functions | |||
built-in function doesn't work properly | Excel Programming |