Hello, is there a hero to help me convert a cell formula to VBA code with a custom function?
The cell formula takes 2 selected values and calculates the difference between them, and then shows the result as "xx % difference".
The difference is always calculated in regards to the higher value:
(higher value - lower value)/higher value * 100 %
So the funktion has to check which vaule is higher and then do the calculation.
The problem is that in the cell there is not always just a number (that would be easy), but sometimes the cell is made of text and numbers e.g. "< LOQ (0.05)", so the formula has to "extract" the number and then calculate further. I have made a cell function but its really long and i have to adjust the cell reference multiple times.
Could someone please make a custom named VBA function where I select the cells and excel does the rest, for example =difference(A1,A2).
This is the function (of course any function that works will be ok too):
IF(OR(A1="< limit ",A2="< limit "),"Value close to or at limit",IFERROR(IF(A1>=A2,ROUND((((A1-A2)/A1)*100),0)&" % Difference",ROUND((((A2-A1)/A2)*100),0)&" % Difference"),IF(--MID(A1,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A1),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A1,".",0),",",0),ROW($1:$100),1)))>=--MID(A2,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A2),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A2,".",0),",",0),ROW($1:$100),1))),ROUND((((--MID(A1,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A1),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A1,".",0),",",0),ROW($1:$100),1)))---MID(A2,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A2),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A2,".",0),",",0),ROW($1:$100),1))))/--MID(A1,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A1),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A1,".",0),",",0),ROW($1:$100),1))))*100),0)&" % Difference",ROUND((((--MID(A2,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A2),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A2,".",0),",",0),ROW($1:$100),1)))---MID(A1,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A1),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A1,".",0),",",0),ROW($1:$100),1))))/--MID(A2,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A2),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A2,".",0),",",0),ROW($1:$100),1))))*100),0)&" % Difference")))
Thank you in advance.
The cell formula takes 2 selected values and calculates the difference between them, and then shows the result as "xx % difference".
The difference is always calculated in regards to the higher value:
(higher value - lower value)/higher value * 100 %
So the funktion has to check which vaule is higher and then do the calculation.
The problem is that in the cell there is not always just a number (that would be easy), but sometimes the cell is made of text and numbers e.g. "< LOQ (0.05)", so the formula has to "extract" the number and then calculate further. I have made a cell function but its really long and i have to adjust the cell reference multiple times.
Could someone please make a custom named VBA function where I select the cells and excel does the rest, for example =difference(A1,A2).
This is the function (of course any function that works will be ok too):
IF(OR(A1="< limit ",A2="< limit "),"Value close to or at limit",IFERROR(IF(A1>=A2,ROUND((((A1-A2)/A1)*100),0)&" % Difference",ROUND((((A2-A1)/A2)*100),0)&" % Difference"),IF(--MID(A1,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A1),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A1,".",0),",",0),ROW($1:$100),1)))>=--MID(A2,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A2),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A2,".",0),",",0),ROW($1:$100),1))),ROUND((((--MID(A1,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A1),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A1,".",0),",",0),ROW($1:$100),1)))---MID(A2,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A2),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A2,".",0),",",0),ROW($1:$100),1))))/--MID(A1,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A1),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A1,".",0),",",0),ROW($1:$100),1))))*100),0)&" % Difference",ROUND((((--MID(A2,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A2),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A2,".",0),",",0),ROW($1:$100),1)))---MID(A1,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A1),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A1,".",0),",",0),ROW($1:$100),1))))/--MID(A2,MIN(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9,".",","},A2),"")),COUNT(--MID(SUBSTITUTE(SUBSTITUTE(A2,".",0),",",0),ROW($1:$100),1))))*100),0)&" % Difference")))
Thank you in advance.