vbaexceldelayadjustable

Adjustable macro delay (by entering time in cell)


Anwser: Change Cell format from D3 into Text instead of General or Time

I'm trying to delay a macro by a variable amount of time.

And I'd like to be able to adjust the amount of delay in my excel workbook without having to open a macro.

I tryed the code below but got :

run time error 13 (Type mismatch).

Is this solvable?

Private Sub CommandButton1_Click()
Dim i As Integer
Dim Response As Integer
    t = Range("D3")
    Application.Wait (Now + TimeValue("t"))

-Cell Format: First Tryed Time (0:00:00), then changed it back to general.

-The data in Cell "D3" : 0:00:00, 0:00:01, 0:30:00 or higher values.

-Time format= General --> t turns out to be something like 0,00000453*E-5 When "D3" is 0:00:01

Time format = time --> t turns out to be empty (using the 37:23:23 time format)


Solution

  • In facts, it is pretty simple mistake, Just changeTimeValue("t") to TimeValue(t)


    Why is that?

    You need to input a time value formatted as text into TimeValue() function, you are getting this value properly into the variable t.

    The problem is when you reuse this, because "t" is a String only containing the t letter and not the variable t!


    Private Sub CommandButton1_Click()
    Dim i As Integer
    Dim Response As Integer
        t = CStr(Range("D3"))
        Application.Wait (Now + TimeValue(t))