Copy with alternance 2 cells (ping-pong)

Maurizio

Well-known Member
Joined
Oct 15, 2002
Messages
682
Office Version
  1. 2007
Platform
  1. Windows
Hi all,
I 'd like a macro able to select-copy as ping pong into a same sheet:

1] If I run macro is selected-copied cell A2:

Range("A2").Select
Range("A2").Copy

2] If I run same macro again [while is active Range("A2").Copy)] is selected-copied, now, cell A5:

Range("A5").Select
Range("A5").Copy

3] and if I re-run macro again I 'd like to go back like 1]

Tia, Maurizio.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

north19701

Active Member
Joined
Jun 17, 2003
Messages
491
Code:
Sub Macro4()
If ActiveCell.Address = Range("a2").Address Then
    [a5].Copy
    ElseIf ActiveCell.Address = Range("a5").Address Then
    [a2].Copy
        Else
        MsgBox ("Neither cell A2 or A5 is the active cell")
End If
End Sub
 

Maurizio

Well-known Member
Joined
Oct 15, 2002
Messages
682
Office Version
  1. 2007
Platform
  1. Windows
Hi north19701,
many thanks for your idea!

This runs OK as I want.

Sub flipflop()
If ActiveCell.Address = Range("a2").Address Then
[a5].Select
[a5].Copy
ElseIf ActiveCell.Address = Range("a5").Address Then
[a2].Select
[a2].Copy
' Else
' MsgBox ("Neither cell A2 or A5 is the active cell")
End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,804
Messages
5,638,455
Members
417,025
Latest member
MusterDuster

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
Top