![]() |
Function working on whim
Hey everyone, first post here. Trying to figure out why a function I have written will work in one cell and not the other. In the case of what I have written, what row the active cell is should not matter but the active cell's column does. It should read a value from a specified row in that column and then perform a simple comparison. My issue is that while in the same column the function will work for one row but not the 2 above it, after those two it begins working again. What have I done to cause this to happen? Here is the code: (simplistic I know but I started learning VBA yesterday) Code: -------------------- Option Explicit Public Function eb(additive2 As Integer) As Double Dim count As Integer additive2 = Application.ThisWorkbook.Worksheets("Results").Cel ls(6, Application.ActiveCell.Column).Value eb = 0 count = 6 For count = 6 To 10 If Application.ThisWorkbook.Worksheets("Additive-Flush").Cells(count, 8).Value = additive2 Then eb = Application.ThisWorkbook.Worksheets("Additive-Flush").Cells(count, 14).Value + eb Else eb = eb + 0 End If Next count End Function -------------------- Thank you for your help. ~Jason -- jclark419 ------------------------------------------------------------------------ jclark419's Profile: http://www.excelforum.com/member.php...o&userid=25430 View this thread: http://www.excelforum.com/showthread...hreadid=388828 |
Function working on whim
My first thought was that your code depends on the current activecell.
If you change that and recalculate, then the result could change. My second thought is that you're passing a variable called additive2. But the first line that does anything, essentially ignores the passed value. jclark419 wrote: Hey everyone, first post here. Trying to figure out why a function I have written will work in one cell and not the other. In the case of what I have written, what row the active cell is should not matter but the active cell's column does. It should read a value from a specified row in that column and then perform a simple comparison. My issue is that while in the same column the function will work for one row but not the 2 above it, after those two it begins working again. What have I done to cause this to happen? Here is the code: (simplistic I know but I started learning VBA yesterday) Code: -------------------- Option Explicit Public Function eb(additive2 As Integer) As Double Dim count As Integer additive2 = Application.ThisWorkbook.Worksheets("Results").Cel ls(6, Application.ActiveCell.Column).Value eb = 0 count = 6 For count = 6 To 10 If Application.ThisWorkbook.Worksheets("Additive-Flush").Cells(count, 8).Value = additive2 Then eb = Application.ThisWorkbook.Worksheets("Additive-Flush").Cells(count, 14).Value + eb Else eb = eb + 0 End If Next count End Function -------------------- Thank you for your help. ~Jason -- jclark419 ------------------------------------------------------------------------ jclark419's Profile: http://www.excelforum.com/member.php...o&userid=25430 View this thread: http://www.excelforum.com/showthread...hreadid=388828 -- Dave Peterson |
All times are GMT +1. The time now is 11:23 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com