# Time difference in VBA vs Worksheet

#### lordriel

##### Board Regular
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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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!

Replies
3
Views
110
Replies
2
Views
207
Replies
10
Views
697
Replies
1
Views
379
Replies
8
Views
183

1,196,250
Messages
6,014,246
Members
441,808
Latest member
xplainer

### 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.

### Which adblocker are you using?

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

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