Consulting

Results 1 to 4 of 4

Thread: set y = “the row number” at which the button I click locates

  1. #1

    set y = “the row number” at which the button I click locates

    Hi,

    I would like to set y = “the row number” at which the button I click locates.
    Eg, If I click the button at row 8, then y would be 8.
    Could you please tell me the code for doing that?

    I hope that when I click the button at a row, a picture named by the text in that row can be inserted.
    Eg, when I click the button at row 8, A.jpg can be inserted.

    Please see the code and diagram below


    [vba]
    Sub Picture_Click

    ‘----------------------------------------------------------------
    ChDir "C:\Users\XX\Desktop\picture\"

    ‘----------------------------------------------------------------
    y = “the row number” at which the button I click locates
    x = Cells(y, 4).Value
    ActiveSheet.Pictures.Insert (x & ".jpg")

    End Sub
    [/vba]

    Thanks

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    [vba]MsgBox ActiveSheet(Application.Caller).TopLeftCell.Address[/vba]

  3. #3
    Quote Originally Posted by mikerickson
    [vba]MsgBox ActiveSheet(Application.Caller).TopLeftCell.Address[/vba]
    Hi,

    I tried it, but my code still does not work
    please see my code below

    thanks

    [VBA]Sub Picture_Click

    ‘----------------------------------------------------------------
    ChDir "C:\Users\XX\Desktop\picture\"

    ‘----------------------------------------------------------------
    y = MsgBox ActiveSheet(Application.Caller).TopLeftCell.Address
    x = Cells(y, 4).Value
    ActiveSheet.Pictures.Insert (x & ".jpg")

    End Sub
    [/VBA]

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    I think you want the .Row property of the .TopLeftCell of the button and it should be taken outside of the MsgBox when used directly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •