PC Review


Reply
Thread Tools Rate Thread

Code needs tweaking :P

 
 
=?Utf-8?B?Sm9jaw==?=
Guest
Posts: n/a
 
      14th Aug 2007
Hi
The following code will automatically insert username, date and time when
data is put into 'B' somewhere:

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Me.Range("B4:B50")) Is Nothing Then
With Target
If .Value <> "" Then
.Offset(0, 8).Value = (UserName)
.Offset(0, 10).Value = Format(Now, "hh:mm:ss")
.Offset(0, 9).Value = Format(Date, "dd/mmm")
End If
End With
End If
End Sub

However, when data is removed from 'B', a debug window appears and the
username etc isn't removed.
If poss, i'd like two versions of this code, the first:
if data is deleted from 'B' username etc is removed too, and
if data is deleted from 'B' username etc remains and is not overwritten

tia,
--
Traa Dy Liooar

Jock
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      14th Aug 2007
It does debug for me, it works fine, although it doesn't add a username
because the code is incomplete.

This clears it if B blanked

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False

If Not Intersect(Target, Me.Range("B4:B50")) Is Nothing Then
With Target
If .Value <> "" Then
.Offset(0, 8).Value = Environ("UserName")
.Offset(0, 10).Value = Format(Now, "hh:mm:ss")
.Offset(0, 9).Value = Format(Date, "dd/mmm")
Else
.Offset(0, 8).Value = ""
.Offset(0, 10).Value = ""
.Offset(0, 9).Value = ""
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub




--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Jock" <(E-Mail Removed)> wrote in message
news:50628E88-E7BE-4142-9B8D-(E-Mail Removed)...
> Hi
> The following code will automatically insert username, date and time when
> data is put into 'B' somewhere:
>
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> If Not Intersect(Target, Me.Range("B4:B50")) Is Nothing Then
> With Target
> If .Value <> "" Then
> .Offset(0, 8).Value = (UserName)
> .Offset(0, 10).Value = Format(Now, "hh:mm:ss")
> .Offset(0, 9).Value = Format(Date, "dd/mmm")
> End If
> End With
> End If
> End Sub
>
> However, when data is removed from 'B', a debug window appears and the
> username etc isn't removed.
> If poss, i'd like two versions of this code, the first:
> if data is deleted from 'B' username etc is removed too, and
> if data is deleted from 'B' username etc remains and is not overwritten
>
> tia,
> --
> Traa Dy Liooar
>
> Jock



 
Reply With Quote
 
=?Utf-8?B?Sm9jaw==?=
Guest
Posts: n/a
 
      14th Aug 2007
Great, thanks Bob.
--
Traa Dy Liooar

Jock


"Bob Phillips" wrote:

> It does debug for me, it works fine, although it doesn't add a username
> because the code is incomplete.
>
> This clears it if B blanked
>
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> On Error GoTo ws_exit:
> Application.EnableEvents = False
>
> If Not Intersect(Target, Me.Range("B4:B50")) Is Nothing Then
> With Target
> If .Value <> "" Then
> .Offset(0, 8).Value = Environ("UserName")
> .Offset(0, 10).Value = Format(Now, "hh:mm:ss")
> .Offset(0, 9).Value = Format(Date, "dd/mmm")
> Else
> .Offset(0, 8).Value = ""
> .Offset(0, 10).Value = ""
> .Offset(0, 9).Value = ""
> End If
> End With
> End If
>
> ws_exit:
> Application.EnableEvents = True
> End Sub
>
>
>
>
> --
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Jock" <(E-Mail Removed)> wrote in message
> news:50628E88-E7BE-4142-9B8D-(E-Mail Removed)...
> > Hi
> > The following code will automatically insert username, date and time when
> > data is put into 'B' somewhere:
> >
> > Private Sub Worksheet_Change(ByVal Target As Range)
> >
> > If Not Intersect(Target, Me.Range("B4:B50")) Is Nothing Then
> > With Target
> > If .Value <> "" Then
> > .Offset(0, 8).Value = (UserName)
> > .Offset(0, 10).Value = Format(Now, "hh:mm:ss")
> > .Offset(0, 9).Value = Format(Date, "dd/mmm")
> > End If
> > End With
> > End If
> > End Sub
> >
> > However, when data is removed from 'B', a debug window appears and the
> > username etc isn't removed.
> > If poss, i'd like two versions of this code, the first:
> > if data is deleted from 'B' username etc is removed too, and
> > if data is deleted from 'B' username etc remains and is not overwritten
> >
> > tia,
> > --
> > Traa Dy Liooar
> >
> > Jock

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
tweaking code =?Utf-8?B?U29waGll?= Microsoft Access VBA Modules 2 4th Feb 2007 04:38 PM
Tweaking Code =?Utf-8?B?UmljaGFyZA==?= Microsoft Excel Programming 3 25th Feb 2006 07:15 PM
Tweaking Code =?Utf-8?B?UmljaGFyZA==?= Microsoft Excel Programming 2 25th Feb 2006 02:23 AM
Tweaking Code - Experts Only! Gordon Microsoft Excel Programming 7 6th Aug 2004 04:09 PM
Help Tweaking this Code Markus Microsoft Excel Programming 2 26th Mar 2004 02:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:15 AM.