Call Sub Routine by selecting Row

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
The code below creates a shape (i.e. Message) when I click on another shape (i.e. Shape A) (works fine). However, I get an error when I just select the row shape A is located. How can I run this sub routine by selecting the row Shape A is located?

VBA Code:
Dim r As Range, Cel As Range
Dim LRow As Long
Dim Shp As Shape

Set Shp = ActiveSheet.Shapes.AddShape(msoShapeRoundedRectangle, 112.5, 112.5, 115, 1)
Set r = ActiveSheet.Shapes(Application.Caller).TopLeftCell
Set Cel = r.Offset(0, 0)

With Shp
    .Name = "Callout"
    .TextFrame.Characters.Text = r.Offset(0, 0).Comment.Text
    .Left = Cel.Left - .Width
    .Top = Cel.Offset().Top
    .Line.Visible = msoFalse
    .TextFrame2.AutoSize = msoAutoSizeShapeToFitText
    .OnAction = "DelCallout"
End With
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Do you still want to be able to run the sub by clicking the shape?
 
Upvote 0
In that case which column is the shape located in?
 
Upvote 0
Ok, how about
VBA Code:
Set Shp = ActiveSheet.Shapes.AddShape(msoShapeRoundedRectangle, 112.5, 112.5, 115, 1)
If IsError(Application.Caller) Then
   Set r = Cells(ActiveCell.Row, "S")
Else
   Set r = ActiveSheet.Shapes(Application.Caller).TopLeftCell
End If
Set Cel = r.Offset(0, 0)
 
Upvote 0
Excellent...Thank you Fluff. I knew I had to use an if statement, but I kept hitting the wall trying to figure out getting around not using the application.caller.

Again...Thank you for helping me.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

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