+ Reply to Thread
Results 1 to 3 of 3

Thread: Need help with Time Stamp Code

  1. #1
    Registered User
    Join Date
    02-13-2006
    Posts
    1

    Need help with Time Stamp Code

    I have written some VBA code which captures a time stamp in column G of the worksheet when the value in columns B or C is changed. (Code pasted below) When a user clicks on a cell in Column B or C it captures the current value, then compares it against the new value if the worksheet is changed. My problem is when more than one cell is selected in columns B or C, the code errors out at the line which it's trying to capture the value of the cell before it is changed (y = target.value). How do I write code into the program to only capture the current value if only one cell is selected. If more than one cell is selected, I don't want the y = target.value line of code to be executed.



    Option Explicit
    Dim y As String
    Dim x As String
    _____________________________________________________________
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)


    y = Target.Value


    End Sub

    ___________________________________________________
    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim x As Long

    x = Target.Row

    If Target.Column = 2 And y <> Target.Value Or Target.Column = 3 And y <> Target.Value Then
    Cells(x, 7) = Time
    Cells(x, 7).NumberFormat = "hh:mm:ss"
    End If

    End Sub

  2. #2
    Toppers
    Guest

    RE: Need help with Time Stamp Code

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Target.Count > 1 Then Exit Sub
    y = Target.Value


    End Sub

    "chkoch99" wrote:

    >
    > I have written some VBA code which captures a time stamp in column G of
    > the worksheet when the value in columns B or C is changed. (Code pasted
    > below) When a user clicks on a cell in Column B or C it captures the
    > current value, then compares it against the new value if the worksheet
    > is changed. My problem is when more than one cell is selected in
    > columns B or C, the code errors out at the line which it's trying to
    > capture the value of the cell before it is changed (y = target.value).
    > How do I write code into the program to only capture the current value
    > if only one cell is selected. If more than one cell is selected, I
    > don't want the y = target.value line of code to be executed.
    >
    >
    >
    > Option Explicit
    > Dim y As String
    > Dim x As String
    > _____________________________________________________________
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    >
    >
    > y = Target.Value
    >
    >
    > End Sub
    >
    > ___________________________________________________
    > Private Sub Worksheet_Change(ByVal Target As Range)
    >
    > Dim x As Long
    >
    > x = Target.Row
    >
    > If Target.Column = 2 And y <> Target.Value Or Target.Column = 3 And
    > y <> Target.Value Then
    > Cells(x, 7) = Time
    > Cells(x, 7).NumberFormat = "hh:mm:ss"
    > End If
    >
    > End Sub
    >
    >
    > --
    > chkoch99
    > ------------------------------------------------------------------------
    > chkoch99's Profile: http://www.excelforum.com/member.php...o&userid=31497
    > View this thread: http://www.excelforum.com/showthread...hreadid=511736
    >
    >


  3. #3
    Tom Ogilvy
    Guest

    Re: Need help with Time Stamp Code

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Count > 1 then exit sub

    .. . .

    --
    Regards,
    Tom Ogilvy




    "chkoch99" <chkoch99.2369by_1139841004.5791@excelforum-nospam.com> wrote in
    message news:chkoch99.2369by_1139841004.5791@excelforum-nospam.com...
    >
    > I have written some VBA code which captures a time stamp in column G of
    > the worksheet when the value in columns B or C is changed. (Code pasted
    > below) When a user clicks on a cell in Column B or C it captures the
    > current value, then compares it against the new value if the worksheet
    > is changed. My problem is when more than one cell is selected in
    > columns B or C, the code errors out at the line which it's trying to
    > capture the value of the cell before it is changed (y = target.value).
    > How do I write code into the program to only capture the current value
    > if only one cell is selected. If more than one cell is selected, I
    > don't want the y = target.value line of code to be executed.
    >
    >
    >
    > Option Explicit
    > Dim y As String
    > Dim x As String
    > _____________________________________________________________
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    >
    >
    > y = Target.Value
    >
    >
    > End Sub
    >
    > ___________________________________________________
    > Private Sub Worksheet_Change(ByVal Target As Range)
    >
    > Dim x As Long
    >
    > x = Target.Row
    >
    > If Target.Column = 2 And y <> Target.Value Or Target.Column = 3 And
    > y <> Target.Value Then
    > Cells(x, 7) = Time
    > Cells(x, 7).NumberFormat = "hh:mm:ss"
    > End If
    >
    > End Sub
    >
    >
    > --
    > chkoch99
    > ------------------------------------------------------------------------
    > chkoch99's Profile:

    http://www.excelforum.com/member.php...o&userid=31497
    > View this thread: http://www.excelforum.com/showthread...hreadid=511736
    >




+ 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.2.0