vba - Application-defined or object-defined error with formula -


i "application-defined or object-defined error" last formula block in code. other 2 work fine, , last formula, when inserted cell, works fine there, too.

any ideas throws error?

sub wells_cartesian_to_spherical() range("m1").value = "boret lengde" range("nj1").value = "asimuth" range("o1").value = "boret helning"  dim rngx2 range set rngx2 = range(cells(2, 2), cells(rows.count, 2).end(xlup)).offset(, 11) rngx2.formula = "=sqrt(((b2-i2)^2+(c2-j2)^2)+(d2-k2)^2)" rngx2.value = rngx2.value  dim rngy2 range set rngy2 = range(cells(2, 2), cells(rows.count, 2).end(xlup)).offset(, 13) rngy2.formula = "=degrees(asin(sqrt((b2-i2)^2+(c2-j2)^2)/(sqrt(((b2-i2)^2+(c2-j2)^2)+(d2-k2)^2))))" 'rngy2.value = rngy2.value  dim rngz2 range set rngz2 = range(cells(2, 2), cells(rows.count, 2).end(xlup)).offset(, 12) rngz2.formula = "=degrees(if(i2-b2>0,(pi()/2)-((atan((j2-c2)/(i2-b2)))),if(i2-b2<0,((3*pi())/2)-((atan((j2-c2)/(i2-b2)))),if(j2-c2<0,pi(),0))))" rngz2.value = rngz2.value end sub 

the formula used calculate depth, orientation , inclination drilled given x, y , z coordinates top , bottom of well. below comma separated sample data should work code:

well no,x,y,z,drilled length,azimuth,inclination,objtype,x bunn,y bunn,z bunn 28738,83124.42153,1233423.379,121,120,0,0,energibrønn,83124.42153,1233423.379,1 29674,87717.14427,1237872.851,139.8000031,135,0,0,energibrønn,87717.14427,1237872.851,4.800003052 29652,90488.64255,1242007.401,229.8000031,201,0,0,energibrønn,90488.64255,1242007.401,28.80000305 28791,90899.79513,1243677.054,274.1000061,114,0,0,energibrønn,90899.79513,1243677.054,160.1000061 29171,88224.0884,1233361.655,127.9000015,102,100,10,energibrønn,88241.53142,1233358.579,27.44961072 30393,88204.31375,1233372.11,127.5999985,160,125,2,energibrønn,88208.88783,1233368.907,-32.30253385 

just copy , paste excel. please excuse norwegian characters/words ;)

well, managed make workaround using r1c1 notation. recorded macro entering formula , copied resulting vba formula code. worked. error must lie somewhere in cell addressing. input, guys.

dim rngz2 range set rngz2 = range(cells(2, 2), cells(rows.count, 2).end(xlup)).offset(, 12) rngz2.formular1c1 = "=degrees(if(rc[-5]-rc[-12]>0,(pi()/2)-((atan((rc[-4]-rc[-11])/(rc[-5]-rc[-12])))),if(rc[-5]-rc[-12]<0,((3*pi())/2)-((atan((rc[-4]-rc[-11])/(rc[-5]-rc[-12])))),if(rc[-4]-rc[-11]<0,pi(),0))))" rngz2.value = rngz2.value 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -