PDA

View Full Version : set y = “the row number” at which the button I click locates



clarksonneo
12-07-2010, 06:57 AM
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



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


Thanks

mikerickson
12-07-2010, 07:57 AM
MsgBox ActiveSheet(Application.Caller).TopLeftCell.Address

clarksonneo
12-08-2010, 08:11 AM
MsgBox ActiveSheet(Application.Caller).TopLeftCell.Address

Hi,

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

thanks

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

mikerickson
12-09-2010, 07:08 AM
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.