Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default Static Now() function

I saw this code in an earlier posting:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'when entering data in a cell in Col B
Application.EnableEvents = False
On Error GoTo enditall
If Target.Cells.Column = 2 Then
n = Target.Row
If Excel.Range("B" & n).Value < "" Then
Excel.Range("A" & n).Value = Now
End If
End If

enditall:
Application.EnableEvents = True
End Sub

I have made adjustments so that it can display the date and time in the
column I want. However,
I get an error which says "Argument not optional".

Please help. Also, would it be possible to adjust it so that it works across
multiple worksheets?

Thank you in advance.

This is sheet event code.

Right-click on the sheet tab and "View Code".

Copy/paste into that module.

Macros must be enabled by the user when opening the workbook for this code to
be
available.

--
Message posted via http://www.officekb.com

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Static Now() function

Worksheet_change only works on one worksheet. You need to copy this code
into each worksheet page you are going to use it for. when you view code,
you will see a project window on the left showing all the worksheets. You
havve to copy the code into each worksheet. double click on each sheet will
bring up a new VBA window where you can place the code.

"sike11 via OfficeKB.com" wrote:

I saw this code in an earlier posting:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'when entering data in a cell in Col B
Application.EnableEvents = False
On Error GoTo enditall
If Target.Cells.Column = 2 Then
n = Target.Row
If Excel.Range("B" & n).Value < "" Then
Excel.Range("A" & n).Value = Now
End If
End If

enditall:
Application.EnableEvents = True
End Sub

I have made adjustments so that it can display the date and time in the
column I want. However,
I get an error which says "Argument not optional".

Please help. Also, would it be possible to adjust it so that it works across
multiple worksheets?

Thank you in advance.

This is sheet event code.

Right-click on the sheet tab and "View Code".

Copy/paste into that module.

Macros must be enabled by the user when opening the workbook for this code to
be
available.

--
Message posted via http://www.officekb.com


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Static Now() function

All the worksheets in the workbook follow the same rule--a change made in column
B means that the date/time will be inserted into column A.

If yes, then you can put this code behind the ThisWorkbook module (not any
particular sheet).

Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

With Target
'one cell at a time
If .Cells.Count 1 Then Exit Sub

'only column B
If Intersect(.Cells, Sh.Range("b:b")) Is Nothing Then
Exit Sub
End If

Application.EnableEvents = False
On Error GoTo EndItAll

If .Value = "" Then
'do nothing
Else
Sh.Cells(.Row, "A").Value = Now
End If
End With

EndItAll:
Application.EnableEvents = True

End Sub

And remove any worksheet_change event that you've added that does the same
stuff.


"sike11 via OfficeKB.com" wrote:

I saw this code in an earlier posting:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'when entering data in a cell in Col B
Application.EnableEvents = False
On Error GoTo enditall
If Target.Cells.Column = 2 Then
n = Target.Row
If Excel.Range("B" & n).Value < "" Then
Excel.Range("A" & n).Value = Now
End If
End If

enditall:
Application.EnableEvents = True
End Sub

I have made adjustments so that it can display the date and time in the
column I want. However,
I get an error which says "Argument not optional".

Please help. Also, would it be possible to adjust it so that it works across
multiple worksheets?

Thank you in advance.

This is sheet event code.

Right-click on the sheet tab and "View Code".

Copy/paste into that module.

Macros must be enabled by the user when opening the workbook for this code to
be
available.

--
Message posted via http://www.officekb.com


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default Static Now() function

Hi Dave,

Thanks for responding so quickly....much appreciated. Some minor adjustments
made to the columns and the code now looks like:

Option Explicit
Public Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

With Target
'one cell at a time
If .Cells.Count 1 Then Exit Sub

'only column E
If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then Exit Sub
End If

Application.EnableEvents = False
On Error GoTo EndItAll

If .Value = "" Then
'do nothing
Else
Sh.Cells(.Row, "F").Value = Now
End If
End With

EndItAll:
Application.EnableEvents = True

End Sub

I then put the code in the "ThisWorkbook" module as you suggested. However, I
am not quite sure how to get it to run. Please bear with me as I am a novice
to writing VBA. Any ideas?

I will be forever grateful for any help.

Regards
Mary.



Dave Peterson wrote:
All the worksheets in the workbook follow the same rule--a change made in column
B means that the date/time will be inserted into column A.

If yes, then you can put this code behind the ThisWorkbook module (not any
particular sheet).

Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

With Target
'one cell at a time
If .Cells.Count 1 Then Exit Sub

'only column B
If Intersect(.Cells, Sh.Range("b:b")) Is Nothing Then
Exit Sub
End If

Application.EnableEvents = False
On Error GoTo EndItAll

If .Value = "" Then
'do nothing
Else
Sh.Cells(.Row, "A").Value = Now
End If
End With

EndItAll:
Application.EnableEvents = True

End Sub

And remove any worksheet_change event that you've added that does the same
stuff.

I saw this code in an earlier posting:

[quoted text clipped - 34 lines]
--
Message posted via http://www.officekb.com



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200704/1

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Static Now() function

First, you'll have to fix a typo:

If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then Exit Sub
End If

Becomes this:

If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then
Exit Sub
End If

or this:
If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then Exit Sub

But not both!

=====
And it should run automatically (if macros are enabled and events are also
enabled) when you type anything into any cell in any worksheet in that workbook.

It should exit the subroutine if your change is to multiple cells--or if your
change isn't in column E.

"sike11 via OfficeKB.com" wrote:

Hi Dave,

Thanks for responding so quickly....much appreciated. Some minor adjustments
made to the columns and the code now looks like:

Option Explicit
Public Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

With Target
'one cell at a time
If .Cells.Count 1 Then Exit Sub

'only column E
If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then Exit Sub
End If

Application.EnableEvents = False
On Error GoTo EndItAll

If .Value = "" Then
'do nothing
Else
Sh.Cells(.Row, "F").Value = Now
End If
End With

EndItAll:
Application.EnableEvents = True

End Sub

I then put the code in the "ThisWorkbook" module as you suggested. However, I
am not quite sure how to get it to run. Please bear with me as I am a novice
to writing VBA. Any ideas?

I will be forever grateful for any help.

Regards
Mary.

Dave Peterson wrote:
All the worksheets in the workbook follow the same rule--a change made in column
B means that the date/time will be inserted into column A.

If yes, then you can put this code behind the ThisWorkbook module (not any
particular sheet).

Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

With Target
'one cell at a time
If .Cells.Count 1 Then Exit Sub

'only column B
If Intersect(.Cells, Sh.Range("b:b")) Is Nothing Then
Exit Sub
End If

Application.EnableEvents = False
On Error GoTo EndItAll

If .Value = "" Then
'do nothing
Else
Sh.Cells(.Row, "A").Value = Now
End If
End With

EndItAll:
Application.EnableEvents = True

End Sub

And remove any worksheet_change event that you've added that does the same
stuff.

I saw this code in an earlier posting:

[quoted text clipped - 34 lines]
--
Message posted via http://www.officekb.com



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200704/1


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default Static Now() function

Hi Dave,

Thanks for this. Typo has been fixed. I just have another question. The first
cell i.e "E1" has a title in it. So the next cell the event should affect is
"E2". How will I adjust the code to reflect this.

What happens is that a bar code reader reads the info but I need a date/time
to show when the info was read. When it is next used, the date and time of
the previous cell should not change.

Any help gratefully accepted.

Mary.

Dave Peterson wrote:
First, you'll have to fix a typo:

If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then Exit Sub
End If

Becomes this:

If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then
Exit Sub
End If

or this:
If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then Exit Sub

But not both!

=====
And it should run automatically (if macros are enabled and events are also
enabled) when you type anything into any cell in any worksheet in that workbook.

It should exit the subroutine if your change is to multiple cells--or if your
change isn't in column E.

Hi Dave,

[quoted text clipped - 81 lines]
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200704/1



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200704/1

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Static Now() function

I don't have a guess at what to do with the barcoder stuff, but you can change
this portion:

If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then Exit Sub

to something like:
If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then Exit Sub
if .row < 2 then exit sub 'added this line

or you could just type in the range you want:
If Intersect(.Cells, Sh.Range("e2:e65536")) Is Nothing Then Exit Sub

(adjust that 65536 to 1meg if you're using xl2007)





"sike11 via OfficeKB.com" wrote:

Hi Dave,

Thanks for this. Typo has been fixed. I just have another question. The first
cell i.e "E1" has a title in it. So the next cell the event should affect is
"E2". How will I adjust the code to reflect this.

What happens is that a bar code reader reads the info but I need a date/time
to show when the info was read. When it is next used, the date and time of
the previous cell should not change.

Any help gratefully accepted.

Mary.

Dave Peterson wrote:
First, you'll have to fix a typo:

If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then Exit Sub
End If

Becomes this:

If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then
Exit Sub
End If

or this:
If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then Exit Sub

But not both!

=====
And it should run automatically (if macros are enabled and events are also
enabled) when you type anything into any cell in any worksheet in that workbook.

It should exit the subroutine if your change is to multiple cells--or if your
change isn't in column E.

Hi Dave,

[quoted text clipped - 81 lines]
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200704/1



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200704/1


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default Static Now() function

Hi Dave,

Thank you very much!! I have managed to get this working and it is great!! I
can't tell you how much I appreciate your help.

Regards,

Mary.

Dave Peterson wrote:
I don't have a guess at what to do with the barcoder stuff, but you can change
this portion:

If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then Exit Sub

to something like:
If Intersect(.Cells, Sh.Range("e:e")) Is Nothing Then Exit Sub
if .row < 2 then exit sub 'added this line

or you could just type in the range you want:
If Intersect(.Cells, Sh.Range("e2:e65536")) Is Nothing Then Exit Sub

(adjust that 65536 to 1meg if you're using xl2007)

Hi Dave,

[quoted text clipped - 42 lines]
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200704/1



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200704/1

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
Inserting a static date into a function FIF780 Excel Worksheet Functions 5 February 1st 07 11:39 PM
How to make the Result of a TODAY Function static? kscramm Excel Worksheet Functions 11 March 23rd 06 09:17 AM
Static Row DY New Users to Excel 5 September 9th 05 01:36 AM
using now() as static function MINAL ZUNKE New Users to Excel 3 June 29th 05 06:04 PM
How can I keep top row in Excel static? Kerouac Excel Discussion (Misc queries) 2 June 20th 05 09:20 PM


All times are GMT +1. The time now is 07:38 AM.

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

About Us

"It's about Microsoft Excel"