I am very new to VBA (this is the first thing I've ever built using it), so I apologize if my terminology is off.
I tried my hand at building a small handful of UDFs to simplify a somewhat annoying task that some of my colleagues and I regularly have to complete. Each of these UDFs essentially takes a multiple-if statement and simplifies it so that instead of having to type...
...someone could just type out...
The UDFs that I created seem to be working fine. However, I want to be able to take the sum of NEWFUNCTION for a range by entering something like
I am having trouble figuring out how to code this in VBA properly, and was hoping for some advice. The code for one of my UDFs is below....
To explain further, here is an example screenshot
This is just a simplified example, but there can be tens of thousands (or more) rows.
Currently, the formula populating C2 is
which is dragged down to C20. It is basically saying, if A is less than B, then A, otherwise B. But there are some intricacies with the way that negative numbers and zero values are treated that are not apparent in the screenshot, which is why the formula appears unnecessarily lengthy.
The formula in D2 and dragged to D20 is
....for which the VBA code is above. You can see in the example screenshot that it ends up with the same result as the pasted if/then formula in C2 and (in row 21) they sum up to the same amount.
The value in F2 (which is the same as either SUM(C2:C20) or SUM(D2:D20), is what I would like to be achievable by entering something like
I am basically trying to remove a step in the process where my colleagues and I would have to type
in Column C, drop it down, and sum it.