To move a range including all its formatting options (such as cell colors, borders, font styles, etc.), you will need to use a method that copies not only the content but also the formatting. Then, after moving the content and formatting, you can clear the original range. Since we are dealing with potential issues of overlapping ranges, the approach using a temporary storage area remains valid. This time, however, we’ll ensure to copy the entire cell content along with its formatting and then clear the formatting from the original range after the move.
Here’s how you can adapt the script to preserve and move formatting:
Sub MoveCellsDownWithFormatting()
Dim destinationRange As Range
Set ws = ThisWorkbook.Sheets("Sheet1")
' Define the source range you want to move
Set sourceRange = ws.Range("F10:F30")
' Choose a temporary location where you can safely copy the source range
' Ensure this temporary location won't overwrite any important data
Set tempRange = ws.Range("Z1") ' Example uses column Z, adjust as needed
' Copy the source range to the temporary location, including content and formatting
sourceRange.Copy Destination:=tempRange
' Clear the contents and formatting of the original source range
sourceRange.ClearContents
' Define the destination range where you want to move the source range
' Adjust the destination to ensure it matches the target start cell
Set destinationRange = ws.Range("F13")
' Move the data from the temporary location to the destination range
' This includes content and formatting
tempRange.Resize(sourceRange.Rows.Count, sourceRange.Columns.Count).Copy
' Paste the copied cells to the destination range
destinationRange.PasteSpecial Paste:=xlPasteAllUsingSourceTheme
' Clear the temporary data including contents and formats
tempRange.Resize(sourceRange.Rows.Count, sourceRange.Columns.Count).ClearContents
tempRange.Resize(sourceRange.Rows.Count, sourceRange.Columns.Count).ClearFormats
Application.CutCopyMode = False
This script copies the cells from the source range to a temporary location, preserving all formatting. Then, it clears both the contents and the formatting of the original cells. After that, it copies the content from the temporary location to the final destination, ensuring all formatting is preserved. Finally, it cleans up the temporary location and the clipboard.
By using PasteSpecial with the xlPasteAllUsingSourceTheme option, we ensure that all the content and formatting are pasted into the destination range. This method ensures that your data and its visual presentation are preserved during the move operation.
To run this updated script, insert it into a new module within the Excel VBA Editor, and execute it as previously described. This should move your range from “F10:F30” to start at “F13”, including all formatting options, without any overlap errors.