Forum Discussion

perkin_warbeck's avatar
perkin_warbeck
Brass Contributor
Aug 21, 2020
Solved

Unable to lock cell formatting

When a user pastes data onto a worksheet, how can I prevent the pasted data from erasing the formatting (cell borders, background color, number formats, etc.)?   The following method (which I found...
  • mtarler's avatar
    mtarler
    Aug 22, 2020

    perkin_warbeck  yes you are correct and I'm sure you read my sample code.  I delete any formats they brought in and then added the new formats.  I apply the new formats to all pasted cells but sounds like you have to be more selective.

    How about a completely different approach where you have them paste the data in a different sheet and then you use VBA to copy and paste values only.

    Or if they past in a different sheet then you just use a formula to reference that data from the sheet with the formats.

    You can also use on selection in VBA to determine where they want to paste the data and then use VBA to paste values or give them a pop-up.  You can lock the entire sheet but allow selection so they can paste anywhere but VBA would do the work instead.

    There are many ways to skin a cat in excel, it's hard to suggest the best option for you without knowing more about the application.

Resources