Quantcast
Channel: Active questions tagged worksheet-function - Super User
Viewing all articles
Browse latest Browse all 988

Converting an Excel formula to a VBA macro

$
0
0

recently i have found a formula and modified it and now it works as i want. It is a formula that calculates the difference between two cells with a certain formatting, like this:

Cell I1: (-100-?-?)

Cell J1: 1000

Result: 900

The formatting can vary, the I1 cell is sometimes just (-?) or (-56-200) without no question marks for example, i need to find how much difference there is between I1 and J1. Now my problem is, i want this to run as a macro and show the result in a message box. I have a couple thousand rows like this and having a column with the formula for each one really slows down my computer so just running the macro would be better.

I want to make a button on the column K2 for example and when i press it, that should calculate it based on the values in I2 and J2 and show it in a message box (or an info bubble). How can i achieve this?

Formula below:

=IF(ISERR(SEARCH("(";I2;1));"";J2-SUM((TRIM(MID(SUBSTITUTE(IF(ISERR(SEARCH("~?";I2;1));(MID(I2;LEN(LEFT(I2;SEARCH("(";I2;1)))+1;LEN(I2)-LEN(LEFT(I2;SEARCH("(";I2;1)))-1));(MID(I2;(LEN(LEFT(I2;SEARCH("(";I2;1)))+1);(LEN(LEFT(I2;SEARCH("~?";I2;1))))-(LEN(LEFT(I2;SEARCH("(";I2;1)))+1)-1)));"-";REPT(" ";255));1+(ROW(I:I)-1)*255;255)) & "0")/10))

I am using Office 365 fyi and the formula is probably not efficient but i couldn't really find a way to convert this to a macro on its own, maybe there is an even better way but i don't know.

Any help is appreciated, Thanks.


Viewing all articles
Browse latest Browse all 988

Trending Articles