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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Add this to the relevant sheet module
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.column <> 1 Then Exit Sub
   Target.Offset(, 3).Copy Target
   Target.Offset(, 2).Copy Target.Offset(, 1)
   Cancel=True
End Sub
and then double click i col A for the row you want to work on
 
Upvote 0
Great. Thank you for showing me. Also, one more if you don't mind. How would you do this if the cells were from the same file but a sheet2 instead of sheet1?

thanks again!
 
Upvote 0
You would need to put that code in every sheet module you want it to work on.
 
Upvote 0
Sorry for the confusion. Something similar to this?

Sub Macro3()
'
' Macro3 Macro
'
'
Sheets("Sheet2").Select
Range("D1").Select
Selection.Copy
Sheets("Sheet1").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("Sheet2").Select
Range("C1").Select
Selection.Copy
Sheets("Sheet1").Select
Range("B1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub
 
Upvote 0
Ok, this would need to go in the Sheet1 module
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.column <> 1 Then Exit Sub
   With Sheets("Sheet2")
      .Range(Target.Offset(, 3).Address).Copy Target
      .Range(Target.Offset(, 2).Address).Copy Target.Offset(, 1)
   End With
   Cancel = True
End Sub
 
Upvote 0
Ok, this would need to go in the Sheet1 module
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.column <> 1 Then Exit Sub
   With Sheets("Sheet2")
      .Range(Target.Offset(, 3).Address).Copy Target
      .Range(Target.Offset(, 2).Address).Copy Target.Offset(, 1)
   End With
   Cancel = True
End Sub

Great! Thank you again. That is what I was after.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
I hope you dont mind if I brought this back up. Everything you have shown makes sense and works. I do have another question within this same process.

Basically its the same except I am trying to copy a range of cells, then also at the end of the sequence, erase the contents of a cell.

Code:
Sub Macro4()
'
' Macro4 Macro
'
'
    Range("A1").Select
    Sheets("Sheet2").Select
    Range("A1:B1").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Sheet1").Select
    Range("A1").Select
    ActiveSheet.Paste
    Range("D1").Select
    Sheets("Sheet2").Select
    Range("D1").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Sheet1").Select
    Range("D1").Select
    ActiveSheet.Paste
    Range("C1").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("A1").Select
End Sub

Again, thank you the help. Greatly appreciate it!
 
Upvote 0
Can you please explain in words what you are trying to do?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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