Help with a VBA code
Closed
amedotero
Posts
7
Registration date
Thursday November 29, 2012
Status
Member
Last seen
December 5, 2012
-
Dec 3, 2012 at 02:42 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Dec 6, 2012 at 07:49 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Dec 6, 2012 at 07:49 AM
Related:
- Help with a VBA code
- Battery reset code - Guide
- Samsung volume increase code - Guide
- How to get whatsapp verification code online - Guide
- Vba case like - Guide
- Cs 1.6 code - Guide
6 responses
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Dec 3, 2012 at 08:16 PM
Dec 3, 2012 at 08:16 PM
Worked for me. what version of excel you are using on. I tried on 2003
I copied your code "Public Sub MyDelKey() " in a new module
and "Private Sub Workbook_Open() " in "ThisWorkbook"
I copied your code "Public Sub MyDelKey() " in a new module
and "Private Sub Workbook_Open() " in "ThisWorkbook"
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
552
Dec 4, 2012 at 10:35 AM
Dec 4, 2012 at 10:35 AM
Hi Amedotero,
You are trying to unlock a cell while the sheet is still protected. Don't know how Rizvisa was able to make it work.
First unlock sheet > unlock cell > clear contents > lock cell > lock sheet.
Best regards,
Trowa
You are trying to unlock a cell while the sheet is still protected. Don't know how Rizvisa was able to make it work.
First unlock sheet > unlock cell > clear contents > lock cell > lock sheet.
Public Sub MyDelKey() ActiveSheet.Unprotect ActiveCell.Locked = False ActiveCell.ClearContents ActiveCell.Locked = True ActiveSheet.Protect End Sub
Best regards,
Trowa
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Dec 4, 2012 at 11:06 AM
Dec 4, 2012 at 11:06 AM
Trowa, i also did what you did. I missed to state that. :)
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
552
Dec 4, 2012 at 11:20 AM
Dec 4, 2012 at 11:20 AM
Good to hear, thought I might have missed something.
Take care.
Take care.
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Dec 4, 2012 at 01:48 PM
Dec 4, 2012 at 01:48 PM
See this file
http://speedy.sh/3JdrQ/amedotero..xlsm
I tested it on Win 7 / office 2010
On delete, it should put "test" in the cell
This was my code that i added in a Module
This was code in "ThisWorkbook"
http://speedy.sh/3JdrQ/amedotero..xlsm
I tested it on Win 7 / office 2010
On delete, it should put "test" in the cell
This was my code that i added in a Module
Public Sub MyDelKey() With ActiveSheet .Unprotect With ActiveCell .Locked = False .ClearContents .Value = "test" End With .Protect End With End Sub
This was code in "ThisWorkbook"
Private Sub Workbook_Open() Application.OnKey "{DELETE}", "MyDelKey" End Sub
amedotero
Posts
7
Registration date
Thursday November 29, 2012
Status
Member
Last seen
December 5, 2012
Dec 4, 2012 at 01:34 PM
Dec 4, 2012 at 01:34 PM
thanks for the comments.
@rizvisa1 I'm using excel 2010
@ TrowaD
Thanks for the correction but still have the same problem. Excel just doesn't run the macro MyDelKey. That's the main problem I have.
@rizvisa1 I'm using excel 2010
@ TrowaD
Thanks for the correction but still have the same problem. Excel just doesn't run the macro MyDelKey. That's the main problem I have.
amedotero
Posts
7
Registration date
Thursday November 29, 2012
Status
Member
Last seen
December 5, 2012
Dec 4, 2012 at 02:08 PM
Dec 4, 2012 at 02:08 PM
the problem I'm having is that excel can't get to the code. I'm unable to test it because I got an error message that says "Cannot run macro 'MyDelKey'. Macro may not be available or all macros may be disable"
I went to Macro Security and enable all macros but still have the problem. Don't know what to do next.
Thanks!
I went to Macro Security and enable all macros but still have the problem. Don't know what to do next.
Thanks!
Didn't find the answer you are looking for?
Ask a question
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Dec 4, 2012 at 02:21 PM
Dec 4, 2012 at 02:21 PM
did you try the sample book ? Did you face same issue ?
amedotero
Posts
7
Registration date
Thursday November 29, 2012
Status
Member
Last seen
December 5, 2012
Dec 4, 2012 at 04:35 PM
Dec 4, 2012 at 04:35 PM
yep.. I just did it and I'm having the same issue. This problem is driving me crazy!
thanks for the feedback
thanks for the feedback
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Dec 4, 2012 at 10:28 PM
Dec 4, 2012 at 10:28 PM
whats is exact error msg text?
amedotero
Posts
7
Registration date
Thursday November 29, 2012
Status
Member
Last seen
December 5, 2012
Dec 5, 2012 at 11:31 AM
Dec 5, 2012 at 11:31 AM
"Cannot run the mocaro C:\User\969678\Desktop\OtProject.xlsm'!MyDelKey'.The macro may not be available on this workbook or all the macros may be disable"
that's the message. I might try it at home maybe my company' policy has disabled the use of macros. Could that be the reason? If so, why I'm able to change settings on Macro security?
that's the message. I might try it at home maybe my company' policy has disabled the use of macros. Could that be the reason? If so, why I'm able to change settings on Macro security?
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Dec 6, 2012 at 07:49 AM
Dec 6, 2012 at 07:49 AM
well that would be easy to test. Why not just run the macro manually to see if it clears the active cell or not. The error msg seems to suggest to me that either macro is not available in active workbook module. But you said that you have downloaded and tested the sample book that I uploaded. I was able to delete the content in that workbook and you said you got an error doing same.