View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Loxley[_3_] Loxley[_3_] is offline
external usenet poster
 
Posts: 1
Default Macro based on command button location?


create your 3 buttons,

in the example below they are in cells L8,M8,N8 although this is not
relevant
as the code for each button press 'moves' the cursor to the activated
column.

this code below will work, but you could tidy it up a bit by making the
column identifier a variable.


Private Sub CommandButton1_Click()

Range("L1").Select ' column the macro button is in

ActiveCell.Offset(6, 10).Range("A1:A22").Select
Selection.Copy
ActiveCell.Offset(9, -10).Range("A1").Select ' this is cell L16
ActiveSheet.Paste

End Sub
Private Sub CommandButton2_Click()

Range("M1").Select ' column the macro button is in

ActiveCell.Offset(6, 9).Range("A1:A22").Select
Selection.Copy
ActiveCell.Offset(9, -9).Range("A1").Select ' this is cell M16
ActiveSheet.Paste

End Sub
Private Sub CommandButton3_Click()

Range("N1").Select ' column the macro button is in

ActiveCell.Offset(6, 8).Range("A1:A22").Select
Selection.Copy
ActiveCell.Offset(9, -8).Range("A1").Select ' this is cell N16
ActiveSheet.Paste

End Sub


--
Loxley
------------------------------------------------------------------------
Loxley's Profile: http://www.excelforum.com/member.php...o&userid=23927
View this thread: http://www.excelforum.com/showthread...hreadid=553652