Hello -
I'm including the following code within another set of Excel VBA that has worked fine. The purpose of the following code is to remove a formula by pasting special values.
When I highlight and run all of the code manually, this newly added code component works. When I run the code by clicking the button it's associated with, the original code continues to work fine, but this newly added code pieced does not.
I don't think it's an Excel worksheet protection issue, as the same issue occurs when I remove all protection.
Help would be greatly appreciated.
Thanks....With Sheet16 ActiveSheet.Unprotect Password:="password" Range("B21:C21").Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False ActiveSheet.Protect Password:="password" Application.CutCopyMode = False End With
Last edited by PasteSpecialValues; 06-16-2011 at 10:59 AM.
Hi PasteSpecialValues
Only guessing without seeing the entire code. You can try modifying the code like thisIf you look carefully, you'll see I changed this line of code by adding a dot (.) before it. This ties the range to the "with" worksheet (Sheet16) and not the active worksheet.With Sheet16 ActiveSheet.Unprotect Password:="password" .Range("B21:C21").Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False ActiveSheet.Protect Password:="password" Application.CutCopyMode = False End With.Range("B21:C21").Select
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
John -
Thanks for your response. When I add the dot before that line a "Run-time error '1004': Select method of Range class failed" message is generated. Any additional thoughts?
Thanks again,
Aaron
Hello Aaron,
Try this method.
With Sheet16 .Unprotect Password:="password" .Range("B21:C21").Value = .Range("B21:C21").Value .Protect Password:="password" End With
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Leith -
That worked, thank you so much!
Aaron
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks