Function not reliably feeding data back?

Cummins

Board Regular
Joined
Jul 26, 2011
Messages
58
I apologize for posting this again. This is an update of an issue I posted yesterday. I forgot to add a tag to that post and Could not see how to update it.

Hope someone can help with this...it is beyond bizzare. I watched this several times now. n = the number of columns of data. When n=4, as t cycles through, section A is accessing section B to pull the data out of the spreadsheet. When t = 3....A1(3) returns as zero. Not ""...zero. The value of "a" strangely is the SAME as it was when t =2. The same thing happens to A2(3) and b. HOWEVER, A3(3) and c get the correct value. Now, when I whatch Section B, the value for FindData is correct when t=3 for each pull. It is not feeding back the value...WHY? It happens the same way EVERY time I run it.





Section A:

For t = 1 To n

DataCol = 11 + t

A1(t) = CInt(FindData("im_Count_TotalSession"))

a = CInt(FindData("im_Count_TotalSession"))

A2(t) = CInt(FindData("im_Count_AccSession"))

b = CInt(FindData("im_Count_AccSession"))

A3(t) = CInt(FindData("im_Count_RejSession"))

c = CInt(FindData("im_Count_RejSession"))



a1sum = a1sum + CInt(A1(t))

a2sum = a2sum + CInt(A2(t))

a3sum = a3sum + CInt(A3(t))



Section B:

Public Function FindData(Data As String) As String

Dim RowNum As Integer

Dim Count As Integer



On Error Resume Next

Set dataobj = ActiveWorkbook.ActiveSheet

If Data <> "" Then

'Looks in this array of cells for the desired item which is stored in "Data"

dataobj.Range(Cells(1, 4), Cells(1000, 4)).Find(Data, LookIn:=xlFormulas, LookAt:=xlWhole).Activate

If Err.Number = 0 Then

FindData = dataobj.Cells(ActiveCell.Row, DataCol).Value



Else

FindData = "???"

End If

Else

FindData = ""

d = Err.Number

End If



End Function
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
It is difficult to interpret the code and understand the behavior unless we can see the data that code is processing in Range(Cells(1, 4), Cells(1000, 4)) and Cells(ActiveCell.Row, DataCol). Is there any way you can share the data?
 
Upvote 0

Forum statistics

Threads
1,215,785
Messages
6,126,887
Members
449,347
Latest member
Macro_learner

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top