xlquestions
New Member
- Joined
- May 2, 2015
- Messages
- 6
Hi!
First off, a little bit of background. I have a spreadsheet workbook which I use for business. It consists of 13 sheets, some with very little data (being used as a day planner), and a couple with a few hundred rows (customer data etc). The entire workbook is currently 575KB. It's an XLSX, Office 2007. I've used this spreadsheet for around 3 years, on a couple of different computers running Windows 7. The various sheets use data validation and conditional formatting to some extent - nothing major.
Over the years, I found that the workbook became increasingly slow and unstable - copying more than one row, in particular, often caused the spreadsheet to hang, "Whitescreen" crash and restart Excel. I tried many solutions such as cutting out unnecessary conditional formatting, removing excess sheets, splitting it into several different workbooks with different sheets in each file etc and nothing ever seemed to work.
A few days ago, prompted by some very annoying repeated crashing (hard to avoid copying lots of rows in, say, the daily planner, every time the week changes!), I dissected the spreadsheet and, after a few hours of digging (including exporting the whole thing as .csv and starting to create a new workbook from scratch), found the culprit - every time I had copied a cell, or set of cells, Excel had been copying (duplicating) the conditional formatting with it, so when I went into the conditional formatting menu I found tens - possibly hundreds - of thousands of duplicate conditional formatting rules. As Excel has no easy way to mass-delete lots of conditional formatting rules (but leave some), I cleared off ALL the conditional formatting and wrote new conditional formatting (hereafter shortened to CF for brevity) rules from scratch.
Bingo! The workbook was back up and running and full speed like new, and I was even able to add back in a few CF rules that I had a long time back but deleted when the spreadsheet got unstable a year or so ago.
Now obviously, I didn't want the same situation to repeat itself so I started researching on the web for a way to "lock" the cells so that cell contents could be copied or cut WITHOUT the CF rules or data validation (Hereafter DV) moving along with it. I found the "paste special" > "Values" option to just copy the text (or double click the cell (or F2) and copy the text, then do the same to the destination cell to paste only text).However, the latter has the issue that you can only paste one cell's worth of info that way, not multiple rows/columns and the former has the issue that, well, it's not very user-friendly. Sure, I can add a "Paste special" icon to the ribbon or quickbar or whatever, but it's just too ingrained in myself and other users to use Ctrl+C or Ctrl+X and Ctrl+V.
I did look into "Lock Cells" but apparently that doesn't work (insofar as keeping the CF and DV grounded in that cell whilst moving data). I found several forum threads and other posts around the web of people asking how to do similar things and having similar problems to my own, and the consensus always seemed to be that it's impossible to lock CF and DV to cells in this way, protected from copy/cut and paste.
After a bit of hunting around though, I did stumble across the following piece of VBA code, posted HERE:
As instructed, I pasted this code in as a VB script module, created a macro for it and bound the macro to Ctrl+V (to replace Windows/Excel's normal Paste option) and it worked fine! I've copied a few cells around within the same sheets that have CF, and no more "copies" of the CF rules are appearing in the CF menu. All seems fine, problem solved....
Except... Now I get errors. Every time I try to copy text from any other program into Excel, any time I try to copy cells in other, completely different, completely unrelated workbooks (whilst the main one is open) within their own workbook, whenever I try to cut rather than copy cells within the main workbook itself (even within the same sheet), I get errors.
For example, I just tried to cut a cell from one location on the same sheet within the main workbook to a different cell location (same workbook, same sheet). Error:
"Microsoft Visual Basic
Run-Time error '1004':
PasteSpecial method of Range class failed
"
Now, I try copying text (a single word) from notepad into an cell on a sheet of the problem workbook:
Same error as above.
Then I open a completely separate spreadsheet workbook (no ties or links to the main one, completely standalone) and try to paste the line of text from Notepad in (with the main sheet still open):
Same error.
Now trying to cut a cell from within that (different) spreadsheet / workbook to another cell on the same sheet:
Same again.
So it seems that this VB script is somehow 'hooking' into Windows' global Ctrl+V, or at least Excel / Office's own weird internal copy/paste clipboard.
---------
So, what I'm looking for is a modification to the above code that will perform the same job (replace Ctrl+V with a script which will always paste as value, allowing me to copy/paste cells in the normal fashion within the main workbook WITHOUT copying the CF / DV behind the scenes stuff). BUT, I'd prefer:
* No hooks outside this spreadsheet, so when this file is open and other excel spreadsheets are open, I can Ctrl+C/Z/V normally in those without the issue of my 'main' workbook catching that
* No errors! Able to copy/cut and paste data from other sources (such as notepad, firefox and maybe other spreadsheets) without errors. Also to be able to cut cells within the same workbook (the main one)
If the above isn't possible, maybe there's another way to 'lock' CF and DV into the sheet so that copy (or cut) and paste won't replicate those entries in the main list (CF), or move (for example) lookup lists from one column to another (with DV). Or, maybe some other way that I can't think of that will make these error messages just go away ^_^.
I've included some screenshots of the error and relevant areas of the spreadsheet. I've only included one screenshot of the error because it's the exact same error whether I'm copying into the main workbook, cutting cells within that workbook, cutting cells (or copying in) to a different workbook while the main is open, etc.
Sorry for the long message and thanks in advance for any assistance with the code! I hope I've covered everything but if you have any questions, please let me know.
First off, a little bit of background. I have a spreadsheet workbook which I use for business. It consists of 13 sheets, some with very little data (being used as a day planner), and a couple with a few hundred rows (customer data etc). The entire workbook is currently 575KB. It's an XLSX, Office 2007. I've used this spreadsheet for around 3 years, on a couple of different computers running Windows 7. The various sheets use data validation and conditional formatting to some extent - nothing major.
Over the years, I found that the workbook became increasingly slow and unstable - copying more than one row, in particular, often caused the spreadsheet to hang, "Whitescreen" crash and restart Excel. I tried many solutions such as cutting out unnecessary conditional formatting, removing excess sheets, splitting it into several different workbooks with different sheets in each file etc and nothing ever seemed to work.
A few days ago, prompted by some very annoying repeated crashing (hard to avoid copying lots of rows in, say, the daily planner, every time the week changes!), I dissected the spreadsheet and, after a few hours of digging (including exporting the whole thing as .csv and starting to create a new workbook from scratch), found the culprit - every time I had copied a cell, or set of cells, Excel had been copying (duplicating) the conditional formatting with it, so when I went into the conditional formatting menu I found tens - possibly hundreds - of thousands of duplicate conditional formatting rules. As Excel has no easy way to mass-delete lots of conditional formatting rules (but leave some), I cleared off ALL the conditional formatting and wrote new conditional formatting (hereafter shortened to CF for brevity) rules from scratch.
Bingo! The workbook was back up and running and full speed like new, and I was even able to add back in a few CF rules that I had a long time back but deleted when the spreadsheet got unstable a year or so ago.
Now obviously, I didn't want the same situation to repeat itself so I started researching on the web for a way to "lock" the cells so that cell contents could be copied or cut WITHOUT the CF rules or data validation (Hereafter DV) moving along with it. I found the "paste special" > "Values" option to just copy the text (or double click the cell (or F2) and copy the text, then do the same to the destination cell to paste only text).However, the latter has the issue that you can only paste one cell's worth of info that way, not multiple rows/columns and the former has the issue that, well, it's not very user-friendly. Sure, I can add a "Paste special" icon to the ribbon or quickbar or whatever, but it's just too ingrained in myself and other users to use Ctrl+C or Ctrl+X and Ctrl+V.
I did look into "Lock Cells" but apparently that doesn't work (insofar as keeping the CF and DV grounded in that cell whilst moving data). I found several forum threads and other posts around the web of people asking how to do similar things and having similar problems to my own, and the consensus always seemed to be that it's impossible to lock CF and DV to cells in this way, protected from copy/cut and paste.
After a bit of hunting around though, I did stumble across the following piece of VBA code, posted HERE:
Code:
Sub PasteasValue()
Selection.PasteSpecial Paste:=xlPasteValues
End Sub
As instructed, I pasted this code in as a VB script module, created a macro for it and bound the macro to Ctrl+V (to replace Windows/Excel's normal Paste option) and it worked fine! I've copied a few cells around within the same sheets that have CF, and no more "copies" of the CF rules are appearing in the CF menu. All seems fine, problem solved....
Except... Now I get errors. Every time I try to copy text from any other program into Excel, any time I try to copy cells in other, completely different, completely unrelated workbooks (whilst the main one is open) within their own workbook, whenever I try to cut rather than copy cells within the main workbook itself (even within the same sheet), I get errors.
For example, I just tried to cut a cell from one location on the same sheet within the main workbook to a different cell location (same workbook, same sheet). Error:
"Microsoft Visual Basic
Run-Time error '1004':
PasteSpecial method of Range class failed
"
Now, I try copying text (a single word) from notepad into an cell on a sheet of the problem workbook:
Same error as above.
Then I open a completely separate spreadsheet workbook (no ties or links to the main one, completely standalone) and try to paste the line of text from Notepad in (with the main sheet still open):
Same error.
Now trying to cut a cell from within that (different) spreadsheet / workbook to another cell on the same sheet:
Same again.
So it seems that this VB script is somehow 'hooking' into Windows' global Ctrl+V, or at least Excel / Office's own weird internal copy/paste clipboard.
---------
So, what I'm looking for is a modification to the above code that will perform the same job (replace Ctrl+V with a script which will always paste as value, allowing me to copy/paste cells in the normal fashion within the main workbook WITHOUT copying the CF / DV behind the scenes stuff). BUT, I'd prefer:
* No hooks outside this spreadsheet, so when this file is open and other excel spreadsheets are open, I can Ctrl+C/Z/V normally in those without the issue of my 'main' workbook catching that
* No errors! Able to copy/cut and paste data from other sources (such as notepad, firefox and maybe other spreadsheets) without errors. Also to be able to cut cells within the same workbook (the main one)
If the above isn't possible, maybe there's another way to 'lock' CF and DV into the sheet so that copy (or cut) and paste won't replicate those entries in the main list (CF), or move (for example) lookup lists from one column to another (with DV). Or, maybe some other way that I can't think of that will make these error messages just go away ^_^.
I've included some screenshots of the error and relevant areas of the spreadsheet. I've only included one screenshot of the error because it's the exact same error whether I'm copying into the main workbook, cutting cells within that workbook, cutting cells (or copying in) to a different workbook while the main is open, etc.
Sorry for the long message and thanks in advance for any assistance with the code! I hope I've covered everything but if you have any questions, please let me know.



