Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Jonathan
 
Posts: n/a
Default Running a macro if any data is entered in a range of cells

Hi

I am totally new to VBA and really need to do some help!

I am writing an excel worksheet to send to students practising for multi
choice exams. They are supposed to press a button when they start the paper
which will then record the start time in a box. I have written a macro that
does this and protects the cell so that the time cannot then be changed but I
want it to automatically run if they answer any questions without pressing
the start button.

My idea for doing this is to use the worksheet_change function to watch the
cells into which the answers would go (namely C12:F37) and if any of those
are changed run the starttime macro.

Can anyone tell me how to do this or give me some code that would work.

Many Thanks

Jonathan
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob Phillips
 
Posts: n/a
Default Running a macro if any data is entered in a range of cells

Jonathan,

Here is the worksheet change code that assumes the time is recorded in A1.
You will need to add protection as well

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "C12:F37"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Me.Range("A1").Value = "" Then
Me.Range("A1").Value = Now
End If
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.




--

HTH

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


"Jonathan" wrote in message
...
Hi

I am totally new to VBA and really need to do some help!

I am writing an excel worksheet to send to students practising for multi
choice exams. They are supposed to press a button when they start the

paper
which will then record the start time in a box. I have written a macro

that
does this and protects the cell so that the time cannot then be changed

but I
want it to automatically run if they answer any questions without pressing
the start button.

My idea for doing this is to use the worksheet_change function to watch

the
cells into which the answers would go (namely C12:F37) and if any of those
are changed run the starttime macro.

Can anyone tell me how to do this or give me some code that would work.

Many Thanks

Jonathan



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Jonathan
 
Posts: n/a
Default Running a macro if any data is entered in a range of cells

Thanks so much for your help Bob,

I have modified your code to add protection and a helpful message box so
it's all working beautifully.

Thanks again

Jonathan

"Jonathan" wrote:

Hi

I am totally new to VBA and really need to do some help!

I am writing an excel worksheet to send to students practising for multi
choice exams. They are supposed to press a button when they start the paper
which will then record the start time in a box. I have written a macro that
does this and protects the cell so that the time cannot then be changed but I
want it to automatically run if they answer any questions without pressing
the start button.

My idea for doing this is to use the worksheet_change function to watch the
cells into which the answers would go (namely C12:F37) and if any of those
are changed run the starttime macro.

Can anyone tell me how to do this or give me some code that would work.

Many Thanks

Jonathan

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob Phillips
 
Posts: n/a
Default Running a macro if any data is entered in a range of cells

That's great Jonathan. Glad to be of help.

Regards

Bob


"Jonathan" wrote in message
...
Thanks so much for your help Bob,

I have modified your code to add protection and a helpful message box so
it's all working beautifully.

Thanks again

Jonathan

"Jonathan" wrote:

Hi

I am totally new to VBA and really need to do some help!

I am writing an excel worksheet to send to students practising for multi
choice exams. They are supposed to press a button when they start the

paper
which will then record the start time in a box. I have written a macro

that
does this and protects the cell so that the time cannot then be changed

but I
want it to automatically run if they answer any questions without

pressing
the start button.

My idea for doing this is to use the worksheet_change function to watch

the
cells into which the answers would go (namely C12:F37) and if any of

those
are changed run the starttime macro.

Can anyone tell me how to do this or give me some code that would work.

Many Thanks

Jonathan



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
Finding min/max of adjacent data in a range of cells Paul987 Excel Worksheet Functions 5 July 15th 05 08:02 PM
save original data after macro is run again MINAL ZUNKE New Users to Excel 3 July 7th 05 12:48 PM
Counting empty cells within a range of cells Rosehill - ExcelForums.com New Users to Excel 0 April 7th 05 12:47 AM
data range Steve M Excel Discussion (Misc queries) 0 April 4th 05 11:17 PM
Macro does not run when data refreshed Larry Lehman Excel Discussion (Misc queries) 0 January 16th 05 07:31 PM


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