testingcode, you could limit the lines to this
Code:
ActiveCell.Value = TimeValue("06:30:00") + TimeSerial(0, Int((150 - 0 + 1) * Rnd + 0), 0)
However, OP wanted to include two time ranges.
Here's one way to do that
Code:
Randomize
If Rnd > 0.5 Then
ActiveCell.Value = (TimeValue("09:00:00") - TimeValue("06:30:00") + 0.0001) * Rnd + TimeValue("06:30:00")
Else
ActiveCell.Value = (TimeValue("14:00:00") - TimeValue("11:45:00") + 0.0001) * Rnd + TimeValue("11:45:00")
End If
Having said that, since the original request was for a formula, this should suffice
=IF(RAND()<0.5,TIME(6,RANDBETWEEN(30,180),0),TIME( 11,RANDBETWEEN(45,180),0))
Bookmarks