Time difference in VBA vs Worksheet

lordriel

Board Regular
Joined
Nov 1, 2005
Messages
68
Office Version
  1. 365
Platform
  1. Windows
Greetings all - let me start out by saying that this board has been a lifesaver for me many times by pointing out things I should have already seen as well as by teaching me things I'd never had the chance to learn. I've spent the past few months retraining an aging VAXBasic brain to think in VBA...and have only been partially successful. Much of the progress is due primarily to everyone (questioners and answerers alike) on this board. Many thanks to all!

On to my question...

I have spent a lot of time reviewing posts concerning determining 'time elapsed' or 'time difference' and have yet to find one that pointedly gives a VBA solution. Currently I'm posting data to a worksheet and using the {=IF(D3>0,MOD(A3-A1,1),"")} and {=IF((A1>A2),(A1-A2),(A2-A1))} equations, then displaying the data on the userform and posting it in various other worksheets.

However, I'd prefer to have it coded in VBA and be free of the worksheet functions altogether. Is this possible, or am I relegated to bouncing the data back and forth?

Thanks!

LR
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
You don't want these formulas to be displayed on the worksheet(s) at all? That can be done, as long as you know where the inputs are coming from.

Something like this: {=IF((A1>A2),(A1-A2),(A2-A1))}

in VBA would look like:

Code:
    Range("D3").FormulaArray = _
        "=IF((R[-2]C[-3]>R[-1]C[-3]),(R[-2]C[-3]-R[-1]C[-3]),(R[-1]C[-3]-R[-2]C[-3]))"

It just depends on where the results go. Try using the macro recorder on a few of these formulas, and definitely use the VBA help files to look up array formulas and R1C1 notation.

Hope that helps!
 
Upvote 0

Forum statistics

Threads
1,213,520
Messages
6,114,101
Members
448,548
Latest member
harryls

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top