# how do you write a macro for the IF function below January 2, 2014 at 23:28:18
Specs: Windows XP
 in excel;A1 = -0.02A2 = -0.03B1 = AVEARGE of A1 + A2 = -0.025If B1 is negative, add A1 and B1, add A2 + B1If B1 is positive, subtract B1 from A1, subtract B1 from A2How do you write this macro? See More: how do you write a macro for the IF function below

#1 January 3, 2014 at 09:48:42
 I'm not 100% clear on what you are asking for.1 - Do you want the macro to perform AVERAGE calculation and place it in B1 and then perform the IF function or do you want the macro to grab the (already averaged) value from B1 and then perform the IF function?2 - Where do you want the new values stored - back in A1 and A2 or someplace else?If it's "someplace else" then it can be done with a cell based formula. Is there a reason you want to use a macro?

Report •

#2
January 3, 2014 at 17:11:00
 Thank you,The new values would be stored in another cell and used to calculate mg/Kg of Copper in soil samples.For this macro, what will the VBA code look like?

Report •

#3 January 4, 2014 at 07:28:30
 You didn't directly answer Question 1 or my final question.I'll try again:1 - Do you want the macro to perform AVERAGE calculation and place it in B1 and then perform the IF function or do you want the macro to grab the (already averaged) value from B1 and then perform the IF function?Final question: Since you said that the "The new values would be stored in another cell" why do you need a macro? A cell based IF function can certainly check the pos/neg status of B1 and do the required calculations.I curious as to why you want to add the complexity of a macro when a cell based formula will work. I'm not saying that the macro will be very complex, because it won't be. I'm just wondering why you want to use a macro instead of a formula to perform this relatively simple task.

Report •
Related Solutions 