Understanding Macros per rows

Mstg007

Active Member
Joined
Dec 30, 2013
Messages
383
I am trying to figure out how to take a macro I have made for Row A.
Then if i were to select another row, it would run the same as it did for Row A.

My example macro:
Sub Macro2()
'
' Macro2 Macro
'
'
Range("D1").Select
Selection.Copy
Range("A1").Select
ActiveSheet.Paste
Range("C1").Select
Application.CutCopyMode = False
Selection.Copy
Range("B1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub

The other part of my question, is getting the macro to be triggered by the desired row.

Thanks for any help.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
How about
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.column = 1 Then
      With Sheets("Sheet2")
         .Range(Target.Offset(, 3).Address).Copy Target
         .Range(Target.Offset(, 2).Address).Copy Target.Offset(, 1)
      End With
      Cancel = True
   ElseIf Target.column = 6 Then
      Sheets("Sheet2").Range(Target.Offset(, 1).Address).Copy Target
      Target.Offset(, -5).Resize(, 4).ClearContents
   End If
End Sub
 
Upvote 0
That hits it! Works. Thank you for putting that together. That's a pretty powerful routine. Again Thank you!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
im sorry to ask this. Someone was wanting to know if on step 2, if it can copy the sheet2 G4 to sheet2 F4 (as well). I am not having much luck. I was guessing to use the destination piece.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.column = 1 Then
      With Sheets("Sheet2")
         .Range(Target.Offset(, 3).Address).Copy Target
         .Range(Target.Offset(, 2).Address).Copy Target.Offset(, 1)
         .Range(Target.Offset(, 3).Address).Copy Destintation:Sheets=(Sheet2).Range
      End With
      Cancel = True
   ElseIf Target.column = 6 Then
      Sheets("Sheet2").Range(Target.Offset(, 1).Address).Copy Target
      Target.Offset(, -5).Resize(, 4).ClearContents
   End If
End Sub
 
Upvote 0
try
Code:
   ElseIf Target.column = 6 Then
      With Sheets("Sheet2").Range(Target.Offset(, 1).Address)
         .Copy Target
         .Copy .Offset(, -1)
      End With
      Target.Offset(, -5).Resize(, 4).ClearContents
   End If
 
Upvote 0
Does that mean it's not working?
 
Upvote 0

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,197
Latest member
k_bs

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