excel udf - Circular Error in VBA User defined Function -
i new vba programming , have written vba function interpolation. attempt input cell c17 , other cell in column cto function "windpressure"
the function gets input column c( height above ground z (m) ) , interpolate design wind pressure, fail due circular error.
the code follow:
function windpressure(z double) double dim row_nos integer dim x1 double dim x2 double dim x3 double dim y1 double dim y2 double dim y3 double ' select first line of data. range("t13").select ' set nos of row interploate row_nos = 12 ' interpolation design wind pressure = 0 row_nos ' case 1: <= 5m if = 0 , z <= activecell.value windpressure = activecell.offset(0, 1).value ' shifting activecell.offset(0, -1).select 'exit if enter if statement exit function elseif >= 0 , z <= activecell.value ' case 2: > 5m x1 = z x2 = activecell.offset(-1, 0).value x3 = activecell.offset(2, 0).value y2 = activecell.offset(-2, 1).value y3 = activecell.offset(2, 0).value y1 = ((x1 - x3) / (x2 - x3) * (y2 - y3)) + y3 windpressure = y1 ' shifting activecell.offset(-1, -1).select 'exit if enter if statement exit function end if activecell.offset(1, 0).select next end function
- could tell me step in script wrong
- is there anyway convenient test function? not procedure execute directly clicking f5 button
many attention , help.
this how debug f5 or f8 procedure:
public sub testme() debug.print windpressure(7) end sub function windpressure(z double) double stop 'the rest of function ' dim row_nos integer ' dim x1 double ' dim x2 double ' dim x3 double end function
now run testme
pressing f8 , enjoy debugging.
another way write ?windpressure(7)
in immediate window , put stop sign in vb editor. go line line.
concerning errors, remove select
part function, vba not allow use there.
Comments
Post a Comment