Excel vba shape row number is different in excel 2016 and 2013


Excel 2016 provides correct row number of shape plus sign where as same code is not providing correct row number in excel 2013.
Below is the code used in macro.

Set b = ActiveSheet.Shapes(Application.Caller)
    With b.TopLeftCell
        lngMyRowNumber = .Row
    End With

Please suggest.

Thank you.
Vishal BharakhadaAsked:
Who is Participating?
Fabrice LambertFabrice LambertCommented:

1st thing, are you sure that ActiveSheet is the correct worksheet ?

I do not advice using such object, as its value depend on user's action, and is by nature chaotic.
As a programmer, you don't want to use chaotic objects.

Prefer referencing explicitly and precisely the object you want to use.
Dim ws as Excel.Worksheet
Set ws = ActiveWorksheet    '// Wrong !! we don't know wich worksheet it is

Set ws = ThisWorkbook.Worksheets(1)    '// Ok, ws is the 1st worksheet

Open in new window

Same goes for ActiveWorkbook, ActiveShape, Selection ect .... never ever use these.
Vishal BharakhadaAuthor Commented:
Hi Fabrice,

Thank you for your comment.

As per your suggestion have tried below code and still there is no luck.

 Dim wb As Workbook
 Dim ws As Worksheet
 Set wb = ThisWorkbook
 Set ws = ThisWorkbook.Worksheets("Additional_Details")
    Set b = ws.Shapes(Application.Caller)
    With b.TopLeftCell
        cs = .Row
    End With

Vishal G. B.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.