Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Run a macro after a cell changes...

Hey,

I have a spreadsheet that I need a macro to exectue after a
particular valued is changed. I have 5 entry feilds I am looking to
attach a time to once it is entered into a spreadsheet. I want it so
that the user enters a value and then the time is inserted next to the
value after it is entered. I have tried the following code but the
problem is that as soon as the time is posted it loops the macro and
then it launches after each time any of the cells is changed on the
macro runs.

Private Sub Worksheet_Change(ByVal Target As Range)
Range("O6").Select
Selection.Copy
Range("O38").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats,
Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
End Sub

I want it so say someone enters a value on A6 it takes the value of A6
and pastes it to T6 and then the time is inserted into T7...the macro
stops. The next time the end users goes to A7 and enters a value it
goes to T8 and then the new time goes to T9. Please help!!!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Run a macro after a cell changes...

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A6:A10" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Range(WS_RANGE)) Is Nothing Then
'copy O to R
Target.Offset(0, 14).Copy
Target.Offset(0, 17).PasteSpecial
Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
End If

ws_exit:
Application.EnableEvents = True
End Sub



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
ps.com...
Hey,

I have a spreadsheet that I need a macro to exectue after a
particular valued is changed. I have 5 entry feilds I am looking to
attach a time to once it is entered into a spreadsheet. I want it so
that the user enters a value and then the time is inserted next to the
value after it is entered. I have tried the following code but the
problem is that as soon as the time is posted it loops the macro and
then it launches after each time any of the cells is changed on the
macro runs.

Private Sub Worksheet_Change(ByVal Target As Range)
Range("O6").Select
Selection.Copy
Range("O38").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats,
Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
End Sub

I want it so say someone enters a value on A6 it takes the value of A6
and pastes it to T6 and then the time is inserted into T7...the macro
stops. The next time the end users goes to A7 and enters a value it
goes to T8 and then the new time goes to T9. Please help!!!



  #3   Report Post  
Posted to microsoft.public.excel.programming
bz bz is offline
external usenet poster
 
Posts: 16
Default Run a macro after a cell changes...

try Application.EnableEvents = False, as shown below.

caution: If you are debugging and turn off events, 'things' stop 'working'
'normally' until you re-enable them!

You NEED the error handler to turn events back on for similar reasons.


wrote in news:1163806139.558065.6980
@f16g2000cwb.googlegroups.com:

Hey,

I have a spreadsheet that I need a macro to exectue after a
particular valued is changed. I have 5 entry feilds I am looking to
attach a time to once it is entered into a spreadsheet. I want it so
that the user enters a value and then the time is inserted next to the
value after it is entered. I have tried the following code but the
problem is that as soon as the time is posted it loops the macro and
then it launches after each time any of the cells is changed on the
macro runs.

Private Sub Worksheet_Change(ByVal Target As Range)


on error goto ex
Application.EnableEvents = False 'stop loop when change.


Range("O6").Select
Selection.Copy
Range("O38").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats,
Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False


ex: Application.EnableEvents = True 'reenable events

End Sub

I want it so say someone enters a value on A6 it takes the value of A6
and pastes it to T6 and then the time is inserted into T7...the macro
stops. The next time the end users goes to A7 and enters a value it
goes to T8 and then the new time goes to T9. Please help!!!




--
bz

please pardon my infinite ignorance, the set-of-things-I-do-not-know is an
infinite set.


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
'IF' Macro to insert cell contents to alternate cell if cell not e Gryndar Excel Worksheet Functions 6 December 20th 08 05:02 PM
using a cell value to control a counter inside a macro and displaying macro value ocset Excel Worksheet Functions 1 September 10th 06 05:32 AM
If cell is empty then run macro otherwise skip this macro [email protected] Excel Programming 3 June 12th 06 03:55 PM
macro to run a separate macro dependent on value in cell scottwilsonx[_13_] Excel Programming 3 July 26th 04 02:30 PM
Question: Cell formula or macro to write result of one cell to another cell Frederik Romanov Excel Programming 1 July 8th 03 03:03 PM


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