Passing Worksheet_Change Target.Row through OnAction

stirlingmw1

Board Regular
Joined
Jun 17, 2016
Messages
53
Office Version
  1. 2016
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
Afternoon
I have a piece of code that adds a Picture to a cell if text is present in column C of that same row and renames the pic to "Tick" & Target.Row.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim shp As Shape
If Not Intersect(Target, Range("C:C")) Is Nothing Then
        If Range("C" & Target.Row).Value <> "" Then

For Each shp In ActiveSheet.Shapes
If shp.Name = "Tick" & Target.Row Then shp.Delete
Next shp
    ActiveSheet.Shapes.Range(Array("Picture 8")).Select
    Selection.Copy
    Range("I" & Target.Row).Select
    ActiveSheet.Paste
    Selection.ShapeRange.IncrementLeft 15.75
    Selection.ShapeRange.Name = "Tick" & Target.Row
    ActiveSheet.Shapes("Tick" & Target.Row).OnAction = "Duplicate"
    Range("D" & Target.Row).Select
       End If
       End If

VBA Code:
Sub Duplicate(ByVal Target)
    ActiveSheet.Range("B" & Target.Row, "F" & Target.Row).Select
    
End Sub

I am trying to add a macro to this picture so if the picture is pressed (OnAction) it copies the range ("B" & Target.row", "F" & Target.row) to the next row down.
the problem I am having is passing the Target.Row from the Worksheet_Change Sub to the Duplicate Sub.

Any ideas what I am doing wrong or not doing?

Thanks

Steve
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You're not passing the row at all. You shouldn't really need to though if the pictures are lined up with the rows in question. In the Duplicate sub you can refer to Activesheet.shapes(application.caller).topleftcell.row to get the row number you need.
 
Upvote 0
Solution
You're not passing the row at all. You shouldn't really need to though if the pictures are lined up with the rows in question. In the Duplicate sub you can refer to Activesheet.shapes(application.caller).topleftcell.row to get the row number you need.

RoryA
Thank you, with your advice and a little tweak it works a treat now.
VBA Code:
Sub Duplicate()
    Dim RowNo As String
    RowNo = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
    ActiveSheet.Range("B" & RowNo + 1, "F" & RowNo + 1).Value = ActiveSheet.Range("B" & RowNo, "F" & RowNo).Value
End Sub

Regards

Steve
 
Upvote 0
RowNo should really be a Long, rather than a String, although it shouldn't matter here.
 
Upvote 0

Forum statistics

Threads
1,214,994
Messages
6,122,633
Members
449,092
Latest member
bsb1122

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