Help needed on Macro

  • Thread starter Thread starter Gary
  • Start date Start date
G

Gary

Hi,

Heres what am trying to accomplish.

two columns (protected), column A - Start Time and Column B End Time.

now when a person starts working he needs to enter the current time
in...say... A1. I want that person to press a key combination that would run
a macro which will unprotect the both the columns, enter the current time in
the Selected cell, and protect both the columns again. same at the time of
End Time.

now I want the macro to enter the date only in the selected cell. but it
should unprotect and Protect both, entire columns. Also, when the columns
are protected, the user should be able to select the cells. please help.

Thanks.
Gary
 
Not sure exactly what you are trying to do, but here are some things to
start you off:

**Enter in the Current Time into active cell

ActiveCell.Value = TimeValue(Now)

**Protect and unprotect a Sheet

ActiveSheet.Protect Password:="your password goes here(inside the
quotes)"

ActiveSheet.Unprotect "your password goes here(inside the quotes)"


Sandy
 
Thanks sandy, this is exactly what am trying to do

The macro would...

1. Unprotect the sheet
2. Enter current time in the active cell.
3. Protect the sheet.

can u please send me the exact code. I dont know coding much.

Thanks again.
 
Gary

Assign this macro to a button or a shortcut key combo.

Sub Enter_Date()
ActiveSheet.Unprotect Password:="justme"
ActiveCell.Value = TimeValue(Now)
ActiveSheet.Protect Password:="justme"
End Sub

Note.....you set up the protection parameters like which columns are locked and
which cells can be selected in the Tools>Protection>Protect sheet dialog.

Enter a password which you will exchange with "justme" in the code above.


Gord Dibben MS Excel MVP
 
Thanks a ton. How do i protect the code?


Gord Dibben said:
Gary

Assign this macro to a button or a shortcut key combo.

Sub Enter_Date()
ActiveSheet.Unprotect Password:="justme"
ActiveCell.Value = TimeValue(Now)
ActiveSheet.Protect Password:="justme"
End Sub

Note.....you set up the protection parameters like which columns are
locked and
which cells can be selected in the Tools>Protection>Protect sheet dialog.

Enter a password which you will exchange with "justme" in the code above.


Gord Dibben MS Excel MVP
 
Oh i got the protection part. Now i have another problem. sorry for being
such a pain.

Is it possible that once the time is entered in that cell, if we press the
button again, it doesnt change?

something like. If the active cell is blank only then run the macro else
give an error message like "You've already entered the time"

Thanks a tonnn for ur help.
 
Sub Enter_Date()
If ActiveCell.Value = "" Then
ActiveSheet.Unprotect Password:="justme"
ActiveCell.Value = TimeValue(Now)
ActiveSheet.Protect Password:="justme"
Else: MsgBox "You have entered the time already"
End If
End Sub


Gord

Oh i got the protection part. Now i have another problem. sorry for being
such a pain.

Is it possible that once the time is entered in that cell, if we press the
button again, it doesnt change?

something like. If the active cell is blank only then run the macro else
give an error message like "You've already entered the time"

Thanks a tonnn for ur help.

Gord Dibben MS Excel MVP
 
Thanks a ton Gord. You Rock.


Gord Dibben said:
Sub Enter_Date()
If ActiveCell.Value = "" Then
ActiveSheet.Unprotect Password:="justme"
ActiveCell.Value = TimeValue(Now)
ActiveSheet.Protect Password:="justme"
Else: MsgBox "You have entered the time already"
End If
End Sub


Gord



Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top