mickyflash
Board Regular
- Joined
- Jan 29, 2009
- Messages
- 77
Hello All
I need a VBA code that copies the active cell, and pastes values 2 cells directly below the active cell. (skips a row). so if the active cell is A1, the target cell would be A3
This code works, until we hit cells that have been merged. The merged cells will always be the same size, and I am only pasting values but cant get it working without breaking the merged cell.
Does anyone have any ideas on a fix for this please?
I need a VBA code that copies the active cell, and pastes values 2 cells directly below the active cell. (skips a row). so if the active cell is A1, the target cell would be A3
This code works, until we hit cells that have been merged. The merged cells will always be the same size, and I am only pasting values but cant get it working without breaking the merged cell.
Does anyone have any ideas on a fix for this please?
VBA Code:
Sub CopyAndPasteTwoCellsBelow()
' Copy the value from the active cell
ActiveCell.Copy
' Move two cells down
Dim targetCell As Range
Set targetCell = ActiveCell.Offset(2, 0)
' Check if the destination cell is not empty
If Not IsEmpty(targetCell.Value) Then
' Ask the user whether to overwrite the existing value
Dim overwrite As VbMsgBoxResult
overwrite = MsgBox("The destination cell is not empty. Do you want to overwrite?", vbYesNo + vbQuestion, "Overwrite Warning")
' Check the user's response
If overwrite = vbNo Then
Exit Sub ' Exit the sub if the user chooses not to overwrite
End If
End If