View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Auric__ Auric__ is offline
external usenet poster
 
Posts: 538
Default How to obtain the transit time

Paul wrote:

Column A I insert a date (Departing date)
Column B I insert another date (Arrival date).

I would like with Vba (vba because sometimes I might need to adjust the
B30 date) once I input a date from cell A30 to obtain in B30 another
date plus a value in A20 (transit time) with the following checks:
- date in B30 = date in A30
- date in B30 = today's date
- date in B30 + A20 (skip Sat. and Sundays)

For example:
Column A20 = 3 (transit time)
Column A30 = 17 jan 2013 (departing time)
Column B30 = 22 jan 2013 (arrival time)


I'm not too clear *why* this needs to be VBA. This could be done with a
simple formula:

=INT((B30-A30)-(INT((B30-A30)/7)*2))

(The inner INT is what handles the weekends.)

If it simply *must* be VBA, try this:

Sub transitTime()
x = Range("B30").Value - Range("A30").Value
Range("A20").Value = x - ((x \ 7) * 2)
End Sub

(Here, "((x \ 7) * 2)" handles the weekends.)

--
The number of arguments is unimportant unless some of them are correct.