excel - VBA UDF fails to call Range.Precedents property -


i trying write simple udf, supposed loop through each of cells of given_row, , pick cells not have precedent ranges, , add values.

here code:

public function totalactualdeductions(given_row integer) integer  total_actual_deduction = 0  present_column = 4 153      set precedent_range = nothing      if cells(2, present_column) = "tds (replace computed figure when deducted)"          on error resume next          set precedent_range = cells(given_row, present_column).precedents          if precedent_range nothing              total_actual_deduction = total_actual_deduction + cells(given_row, present_column)          end if      end if  next  totalactualdeductions = total_actual_deduction  end function 

if try run modifying top declaration, from:

public function totalactualdeductions(given_row integer) integer 

to:

public function totalactualdeductions() given_row = 4 

then runs successfully, , expected. picks cells match criteria, , good.

however, when try run proper udf worksheet, not work. apparently, excel treats cells have no precedents, though have precedents, when call function worksheet.

i don't know why happens, or if range.precedents property supposed behave this.

how can fixed?

after lot of searching, encountered this:

when called excel vba udf, range.precedents returns range , not precedents. there workaround?

apparently, "any call .precedents in call stack includes udf gets handled differntly".

so, did use range.formula "=[a-za-z]" , because satisfied simple purpose. in no way ideal alternative range.precedents property.

foe more detailed explanation, please visit link.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -