Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 23
Default input info when pasted in cells

Hello.
I have this bit of code thats set as a change event in my spreadhseet. So basically when something is entered in column A it updates info columns D,E,F,G. (so i can see who did something and when).
However this only work if the user types info in but not if they copy and paste a load in at a time. So for example if they pasted in 100 entries into column A, then the other columns won't update.
how can i change the code to deal with pasting? (i have tried the different change events in the spreadsheet coding but nothing works. Thanks in advance.

Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, Range("A:A")) Is Nothing Or Target.Cells.Count 1 Then Exit Sub
Target.Offset(0, 2).Value = "OBJECT"
Target.Offset(0, 3).Value = Application.UserName
Target.Offset(0, 4).Value = Date
Target.Offset(0, 5).Value = Range("B2")
Target.Offset(0, 6).Value = Date + 160


End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default input info when pasted in cells

Hi,

Am Tue, 18 Dec 2012 18:31:55 +0000 schrieb kardifflad:

If Intersect(Target, Range("A:A")) Is Nothing Or Target.Cells.Count
1 Then Exit Sub


change to :
If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default input info when pasted in cells

Hello,

Two other quick recommendations. First, you may want to disable events while this code runs so that the cells being updated don't continually run the procedure. The other suggestion is to change the "Target.Offset..." line to "Intersect(Target, Range"A:A")).Offset...". This way, if someone pastes data into a range that includes not only column A, but other columns as well, the offset formula will keep the tracking information in the proper columns.

Here is an updated procedure to illustrate:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
Application.EnableEvents = False
With Intersect(Target, Range("A:A"))
.Offset(0, 2).Value = "OBJECT"
.Offset(0, 3).Value = Application.UserName
.Offset(0, 4).Value = Date
.Offset(0, 5).Value = Range("B2")
.Offset(0, 6).Value = Date + 160
End With
Application.EnableEvents = True
End Sub
  #4   Report Post  
Junior Member
 
Posts: 23
Default

thank you. This worked excellent until i run another macro in my workbook. The other macro copies all the data from this book into another one, after it has copied the data it then deletes it from the current workbook by using .Clearcontents.
however when it clears the contents the worksheet change code youve given me kicks in and enters data in the offset cells in the same way it would if data was copied into them.
so for some reason when clearing contents it is also thinking data is being entered. Is that easily fixable or should i perhaps look to remove this code from my worksheet change code and instead have this onformation updated when i run the macro that copies the data?? (if that makes sense)

Thank you
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default input info when pasted in cells

Hello,

All you'll need to do is disable events right before the .ClearContents line and then enable them again right after it. For example:

Application.EnableEvents = False
Range("A:A").ClearContents
Application.EnableEvents = True



  #6   Report Post  
Junior Member
 
Posts: 23
Default

oh course. how simple!! a Homer Simpson moment me thinks.

Thanks for your help.
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
Copied info from Excel worksheet, but pasted info won't work in fo KRISTENV Excel Discussion (Misc queries) 3 January 8th 09 03:13 PM
Copy info into empty cells below info, until finds cell with new d Fat Jack Utah Excel Discussion (Misc queries) 3 November 16th 08 08:34 PM
How to stop info from being pasted into a cell that has a drop dow lorettal Excel Worksheet Functions 2 October 6th 08 05:30 PM
need help w/ macro prompting with info and pasting the info based on user input drgka55 Excel Programming 8 August 28th 06 06:05 PM
Create form that can't be chg'd but info can be copied/pasted? CHELSEAatENVIRONMENTAL Excel Discussion (Misc queries) 0 May 9th 05 06:57 PM


All times are GMT +1. The time now is 06:46 PM.

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"