CodexBloom - Programming Q&A Platform

Excel: How to Preserve Cell Comments When Copying to a New Workbook in VBA?

👀 Views: 0 đŸ’Ŧ Answers: 1 📅 Created: 2025-07-31
excel vba copy comments

I keep running into I recently switched to After trying multiple solutions online, I still can't figure this out... Hey everyone, I'm running into an issue that's driving me crazy... I'm trying to copy a range of cells from one workbook to another using VBA, but I noticed that the comments attached to the cells are not being copied over. I'm using Excel 2019 and the following code: ```vba Sub CopyRangeWithComments() Dim sourceWorkbook As Workbook Dim targetWorkbook As Workbook Dim sourceWorksheet As Worksheet Dim targetWorksheet As Worksheet Dim sourceRange As Range Dim targetRange As Range Set sourceWorkbook = ThisWorkbook Set targetWorkbook = Workbooks.Add Set sourceWorksheet = sourceWorkbook.Sheets("Sheet1") Set targetWorksheet = targetWorkbook.Sheets(1) Set sourceRange = sourceWorksheet.Range("A1:B10") sourceRange.Copy targetWorksheet.Range("A1") ' The comments are missing here End Sub ``` I've tried using the `PasteSpecial` method, but it doesn't seem to have an option for comments. I've also looked into the `Comment` property, but that feels cumbersome to implement for each cell. My goal is to keep the comments intact without having to manually copy them. Is there a way to efficiently copy both the cell contents and their comments? Any suggestions would be greatly appreciated! My development environment is Windows. This is part of a larger web app I'm building. How would you solve this? For context: I'm using Vba on Debian. I'd be grateful for any help. Any help would be greatly appreciated!