Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Error proofing automatic updating a cell

I have written a sub using a worksheet_change_event to place the date in
the first column of a row, whenever data is placed in any other cell in
that row. The following works fine:

Private Sub Worksheet_Change(ByVal Target As Range)
ActiveCell.EntireRow.Cells(0, 1).Value =
Worksheets("Client").Range("A2")
End Sub

(A2 is the source date)
The problems is if the user intends to add data to the next empty row,
but instead inadvertently changes data in a cell in a row already
containing data (and a date) thereby changing the date. What approach
is the cleanest?

Thanks,




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Error proofing automatic updating a cell

Hi Kls,

Assuming that the entry in the first cell of the row is determined by the
first entry in the row, try:

Private Sub Worksheet_Change(ByVal Target As Range)
If IsEmpty(Cells(Target.Row, 1)) Then
If Not IsEmpty(Target) Then
Cells(Target.Row, 1).Value = _
Worksheets("Client").Range("A2")
End If
End If
End Sub


---
Regards,
Norman



"kls" wrote in message
...
I have written a sub using a worksheet_change_event to place the date in
the first column of a row, whenever data is placed in any other cell in
that row. The following works fine:

Private Sub Worksheet_Change(ByVal Target As Range)
ActiveCell.EntireRow.Cells(0, 1).Value =
Worksheets("Client").Range("A2")
End Sub

(A2 is the source date)
The problems is if the user intends to add data to the next empty row,
but instead inadvertently changes data in a cell in a row already
containing data (and a date) thereby changing the date. What approach
is the cleanest?

Thanks,




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Error proofing automatic updating a cell

Private Sub Worksheet_Change(ByVal Target As Range)
if Target(1).column < 1 then
if isemtpy(cells(Target(1).row,1)) then
cells(target(1).row,1).Value = Date
End If
end If
End Sub

--
Regards,
Tom Ogilvy

"kls" wrote in message
...
I have written a sub using a worksheet_change_event to place the date in
the first column of a row, whenever data is placed in any other cell in
that row. The following works fine:

Private Sub Worksheet_Change(ByVal Target As Range)
ActiveCell.EntireRow.Cells(0, 1).Value =
Worksheets("Client").Range("A2")
End Sub

(A2 is the source date)
The problems is if the user intends to add data to the next empty row,
but instead inadvertently changes data in a cell in a row already
containing data (and a date) thereby changing the date. What approach
is the cleanest?

Thanks,




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Error proofing automatic updating a cell


Hi Tom, thanks for all your help and the new approach.

I inserted a new worksheet and copy/pasted your code, (I corrected the
isempty), but the change event failed to insert a date in col 1 of the
row.

I am unfamiliar w/ target as an object and it is not available in help.
I don't know if I've done something wrong there, or if I am missing
something else. I'd like to know how to use this.

If I do use this, does your code prevent a user from mistakenly getting
into a row that has data in it (and a date in col1 of the row) and
messing everything up? If I lock the cells and protect the workbook,
would the user still be able to added data in unused, subsequent rows or
do I need to do some conditional formatting? (I'm new and haven't yet
figured the ins and outs of locking,protecting etc while allowing user
access to "unused rows and columns".


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Error proofing automatic updating a cell


Tom, having corrected the isempty did fix everything when I went back to
double check after the post. (A new date was not inserted when col1 in
the row already had a date in it). I'm still not sure about using
"Target", but will workout the locking and protections issues.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Error proofing automatic updating a cell

You are correct. I misspelled isempty.

--
Regards,
Tom Ogilvy

"kls" wrote in message
...

Tom, having corrected the isempty did fix everything when I went back to
double check after the post. (A new date was not inserted when col1 in
the row already had a date in it). I'm still not sure about using
"Target", but will workout the locking and protections issues.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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
I want to checkoff items as I'm proofing them RobinB Excel Discussion (Misc queries) 2 March 25th 09 01:33 AM
cell values/automatic updating megspullingherhairout Excel Discussion (Misc queries) 0 September 10th 08 01:22 PM
Tamper proofing flint Excel Discussion (Misc queries) 2 April 25th 07 01:24 PM
Automatic updating Steve Long Excel Programming 0 May 6th 04 06:52 PM
automatic updating cell j feka Excel Programming 3 July 9th 03 02:01 AM


All times are GMT +1. The time now is 01:51 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"