Moving comments along with cell data

Chewyhairball

Active Member
Joined
Nov 30, 2017
Messages
312
Office Version
  1. 365
Platform
  1. Windows
Hi

The following code when run moves the current selected cell and the 5 cells to the right to whatever destination cell is selected in the Inputbox.
It works good but I cannot figure out how to also move any comments that might be in a cell. Specifically the 5th offset cell.

I have wasted the best part of a day trying all sorts but nothing works :(
As usual any help is greatly appreciated :)
VBA Code:
Sub MoveCells()
Dim fromrange As Range
Dim torange As Range

Set torange = Application.InputBox(Title:="Select Destination", prompt:="Select where you want to item/s to be moved to then click OK", Type:=8)
Set fromrange = Range(ActiveCell, ActiveCell.Offset(0, 5))

Range(torange, torange.Offset(0, 5)).Value = fromrange.Value
fromrange.ClearContents

End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
VBA Code:
Range(torange, torange.Offset(0, 5)).Value = fromrange.Value
Use copy/paste instead of range value assignment statements like the one above.
VBA Code:
Sub MoveCells()
    Dim fromrange As Range
    Dim torange As Range
    
    On Error Resume Next
    Set torange = Application.InputBox(Title:="Select Destination", prompt:="Select where you want to item/s to be moved to then click OK", Type:=8)
    On Error GoTo 0
    
    If Not torange Is Nothing Then
        Set fromrange = ActiveCell.Resize(1, 6)
        fromrange.Copy
        torange.PasteSpecial xlPasteValues
        torange.PasteSpecial xlPasteComments
        fromrange.ClearContents
    End If
End Sub
 
Upvote 0
Solution
VBA Code:
Range(torange, torange.Offset(0, 5)).Value = fromrange.Value
Use copy/paste instead of range value assignment statements like the one above.
VBA Code:
Sub MoveCells()
    Dim fromrange As Range
    Dim torange As Range
   
    On Error Resume Next
    Set torange = Application.InputBox(Title:="Select Destination", prompt:="Select where you want to item/s to be moved to then click OK", Type:=8)
    On Error GoTo 0
   
    If Not torange Is Nothing Then
        Set fromrange = ActiveCell.Resize(1, 6)
        fromrange.Copy
        torange.PasteSpecial xlPasteValues
        torange.PasteSpecial xlPasteComments
        fromrange.ClearContents
    End If
End Sub
Hi

Thanks for the reply. I can't use copy and paste. I chose the .value way of doing it as I didn't want to also copy and paste any conditional formatting in the cells.

Rory
 
Upvote 0
VBA Code:
Range(torange, torange.Offset(0, 5)).Value = fromrange.Value
Use copy/paste instead of range value assignment statements like the one above.
VBA Code:
Sub MoveCells()
    Dim fromrange As Range
    Dim torange As Range
   
    On Error Resume Next
    Set torange = Application.InputBox(Title:="Select Destination", prompt:="Select where you want to item/s to be moved to then click OK", Type:=8)
    On Error GoTo 0
   
    If Not torange Is Nothing Then
        Set fromrange = ActiveCell.Resize(1, 6)
        fromrange.Copy
        torange.PasteSpecial xlPasteValues
        torange.PasteSpecial xlPasteComments
        fromrange.ClearContents
    End If
End Sub
Thanks riv01. That works great!
 
Upvote 0

Forum statistics

Threads
1,215,621
Messages
6,125,884
Members
449,268
Latest member
sGraham24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top