+ Reply to Thread
Results 1 to 2 of 2

If/Then/Else formulas in macros

  1. #1
    Forum Contributor
    Join Date
    12-16-2004
    Posts
    125

    If/Then/Else formulas in macros

    I am new to VB/macros but want to know if this is possible. I have created a workbook to quickly and easily record times for runners. I have assigned a macro to a button titled "start" which inserts the current time in cell A1. Then I have created several numbered buttons that put the current time next to a runners name. A formula subtracts the difference to get the time.

    What I now want to do is be able to get a split time by pressing the button for a second time. What I need the macro to do is on the first press of a button put the current time in cell A3, on the second press of the same button place the current time in cell B3, and on the third press of the same button place the current time in cell C3. Is this possible and how, or is there a better way to accomplish this?

    Here is the current macro I recorded.

    Sub Finish_01()
    '
    ' Finish_01 Macro
    ' Macro recorded 10/11/2005 by CJ_22
    '

    '
    Range("F5").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=NOW()"
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Range("A1").Select
    End Sub

    Thanks for any reply.

  2. #2
    Zack Barresse
    Guest

    Re: If/Then/Else formulas in macros

    Hi there,

    If you do not have anything else in row 3, you could use something like this
    ....

    Sub try_this()
    Cells(3, columns.count).end(xltoleft).offset(0, 1).value = time
    End sub

    Format row 3 as desired.

    HTH

    --
    Regards,
    Zack Barresse, aka firefytr


    "CJ-22" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I am new to VB/macros but want to know if this is possible. I have
    > created a workbook to quickly and easily record times for runners. I
    > have assigned a macro to a button titled "start" which inserts the
    > current time in cell A1. Then I have created several numbered buttons
    > that put the current time next to a runners name. A formula subtracts
    > the difference to get the time.
    >
    > What I now want to do is be able to get a split time by pressing the
    > button for a second time. What I need the macro to do is on the first
    > press of a button put the current time in cell A3, on the second press
    > of the same button place the current time in cell B3, and on the third
    > press of the same button place the current time in cell C3. Is this
    > possible and how, or is there a better way to accomplish this?
    >
    > Here is the current macro I recorded.
    >
    > Sub Finish_01()
    > '
    > ' Finish_01 Macro
    > ' Macro recorded 10/11/2005 by CJ_22
    > '
    >
    > '
    > Range("F5").Select
    > Application.CutCopyMode = False
    > ActiveCell.FormulaR1C1 = "=NOW()"
    > Selection.Copy
    > Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
    > SkipBlanks _
    > :=False, Transpose:=False
    > Range("A1").Select
    > End Sub
    >
    > Thanks for any reply.
    >
    >
    > --
    > CJ-22
    > ------------------------------------------------------------------------
    > CJ-22's Profile:
    > http://www.excelforum.com/member.php...o&userid=17551
    > View this thread: http://www.excelforum.com/showthread...hreadid=503191
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1