Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need help with Time Stamp Code


I have written some VBA code which captures a time stamp in column G o
the worksheet when the value in columns B or C is changed. (Code paste
below) When a user clicks on a cell in Column B or C it captures th
current value, then compares it against the new value if the workshee
is changed. My problem is when more than one cell is selected i
columns B or C, the code errors out at the line which it's trying t
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 valu
if only one cell is selected. If more than one cell is selected,
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 An
y < Target.Value Then
Cells(x, 7) = Time
Cells(x, 7).NumberFormat = "hh:mm:ss"
End If

End Su

--
chkoch9
-----------------------------------------------------------------------
chkoch99's Profile: http://www.excelforum.com/member.php...fo&userid=3149
View this thread: http://www.excelforum.com/showthread.php?threadid=51173

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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" wrote in
message ...

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Time Stamp Ken Excel Discussion (Misc queries) 2 May 5th 10 01:15 PM
Time Stamp FARAZ QURESHI Excel Discussion (Misc queries) 8 January 8th 07 11:51 PM
Time Stamp Andrew C Excel Worksheet Functions 2 July 27th 06 05:25 AM
time stamp jiwolf Excel Worksheet Functions 4 December 20th 05 07:18 PM
time stamp a cell that doesn,t change when time stamping another RC Excel Programming 5 October 13th 05 02:52 AM


All times are GMT +1. The time now is 05:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"