What This VBA Code Does
Lars-Erik reached out to me via Facebook with an interesting code concept that would prevent Excel from automatically re-formatting data when pasted in. This is most prevalent when your data includes hyphens or forward slashes to which Excel assumes are associated with dates.
For example, if you were to try typing in "1-15" into your spreadsheet, Excel automatically formats this as "15-Jan" and even worse, changes the cell value all together to 42750 (the numerical date value).
If you copy your data and paste it into Excel with the below macro, you won't have to worry about any of your data being confused for dates by Excel.
'PURPOSE: Paste Data From Clipboard Without Allowing Excel To Auto-Format
'AUTHOR: Lars-Erik Sørbotten
Dim PasteArea As Range
Application.ScreenUpdating = False
'Paste Data To Spreadsheet
'Store The Size Of The Data To A Variable
Set PasteArea = Selection
'Change Paste Area Number Format To Not Reformat Data
PasteArea.EntireColumn.NumberFormat = "@"
'Re-Paste Clipboard Data to Spreadsheet
How Do I Modify This To Fit My Specific Needs?
Chances are this post did not give you the exact answer you were looking for. We all have different situations and it's impossible to account for every particular need one might have. That's why I want to share with you: My Guide to Getting the Solution to your Problems FAST! In this article, I explain the best strategies I have come up with over the years to getting quick answers to complex problems in Excel, PowerPoint, VBA, you name it!
I highly recommend that you check this guide out before asking me or anyone else in the comments section to solve your specific problem. I can guarantee 9 times out of 10, one of my strategies will get you the answer(s) you are needing faster than it will take me to get back to you with a possible solution. I try my best to help everyone out, but sometimes I don't have time to fit everyone's questions in (there never seem to be quite enough hours in the day!).
I wish you the best of luck and I hope this tutorial gets you heading in the right direction!