Here's the corrected VBA code that should work for you:
XlPasteType enumeration (Excel) | Microsoft Learn
=================================
Sub PasteValuesAndSourceFormats()
Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub
=================================
This code will paste the copied selection as values and source formatting into the currently selected cell.
Thanks for the quick reply!
That's different from what I was looking for—your code pastes everything (including the formulas), while I want just the values and source formatting. However, using your very helpful syntax as a starting point, I was able to get a working macro:
=================================
Sub PasteValuesAndSourceFormats()
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub
=================================
This seems to run fine, but is it the technically correct way to write it? I just want to ensure it's not going to fail in unexpected ways.
Also, can you recommend a good beginner's reference guide to writing these macros?