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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
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

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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