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


Hi all,

I'm hoping someone can help get me out of a pickle before by brain
melts.

I am using the following macro in my worksheet -

worksheets(\"stats\").activate
activecell.offset(rowoffset:=0, columnoffset:=1).activate
selection.copy
selection.pastespecial paste:=xlvalues, operation:=xlnone,
skipblanks:= _
false, transpose:=false

I am trying to figure out how to launch this macro, when a cell is
updated. (If this is possible)

Basically, I have a stats spreadsheet for tracking work, and need to
capture the time a piece of work is completed.

Column B will record this by using this formula-

=IF(A1="y",NOW(),"Outstanding")

Then, when cell A1 is updated with a 'Y' to indicate the work is
complete, the current time is recorded in B1. Then by running the
macro, the time is fixed and will not change (as the NOW() function
will continually update).

If I can get the macro to run when A1 is updated, my problem is
solved.

I have considered using a checkbox or button to run the macro. There
are a couple of problems with this. Firstly, as the worksheet may
contain thousands of rows it is time consuming to duplicate the object
in each row. Secondly, when the object is selected/clicked - there is
no guarantee that A1 will be the activecell - meaning the macro will
not do it's intended job.

Could also use shapes - which can be linked to the corresponding cell
to work around this potential problem. However, same issue - with
thousands of rows - I will have to update each shapes cell link.

Any help would be greatfully accepted!!!!

Cheers

Rob


--
systemx
------------------------------------------------------------------------
systemx's Profile: http://www.excelforum.com/member.php...o&userid=29254
View this thread: http://www.excelforum.com/showthread...hreadid=490997

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Run a macro when a cell is updated

In the sheet that you will contain those cells, add

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:A10"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
.Value = Format(Now, "dd m yyyy hh:mm:ss")
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


Change the range A1:A10 to suit.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"systemx" wrote in
message ...

Hi all,

I'm hoping someone can help get me out of a pickle before by brain
melts.

I am using the following macro in my worksheet -

worksheets(\"stats\").activate
activecell.offset(rowoffset:=0, columnoffset:=1).activate
selection.copy
selection.pastespecial paste:=xlvalues, operation:=xlnone,
skipblanks:= _
false, transpose:=false

I am trying to figure out how to launch this macro, when a cell is
updated. (If this is possible)

Basically, I have a stats spreadsheet for tracking work, and need to
capture the time a piece of work is completed.

Column B will record this by using this formula-

=IF(A1="y",NOW(),"Outstanding")

Then, when cell A1 is updated with a 'Y' to indicate the work is
complete, the current time is recorded in B1. Then by running the
macro, the time is fixed and will not change (as the NOW() function
will continually update).

If I can get the macro to run when A1 is updated, my problem is
solved.

I have considered using a checkbox or button to run the macro. There
are a couple of problems with this. Firstly, as the worksheet may
contain thousands of rows it is time consuming to duplicate the object
in each row. Secondly, when the object is selected/clicked - there is
no guarantee that A1 will be the activecell - meaning the macro will
not do it's intended job.

Could also use shapes - which can be linked to the corresponding cell
to work around this potential problem. However, same issue - with
thousands of rows - I will have to update each shapes cell link.

Any help would be greatfully accepted!!!!

Cheers

Rob


--
systemx
------------------------------------------------------------------------
systemx's Profile:

http://www.excelforum.com/member.php...o&userid=29254
View this thread: http://www.excelforum.com/showthread...hreadid=490997




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
How to enable macro and updated link without confirmation? Eric Excel Discussion (Misc queries) 1 April 14th 09 06:56 AM
Excel cells randomly don't get updated unless each cell is updated Lost in Excel Excel Discussion (Misc queries) 5 September 29th 08 06:56 PM
Run Macro(save workbook) after cell updated titch New Users to Excel 3 February 5th 06 07:55 PM
Macro not running when cell value is updated Jon[_21_] Excel Programming 1 November 5th 05 06:22 AM
Macro to Keep Linked Workbooks Updated Karl Burrows Excel Programming 0 January 15th 04 05:59 AM


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

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

About Us

"It's about Microsoft Excel"