Inserting photo into userform using a variable

billyshears

Board Regular
Joined
Aug 29, 2013
Messages
61
My userform has a photo area.

I want the userform to operate so when I click the button to bring it up, the photo that comes up with the userform to be based on a cell value on the active worksheet.

For instance, when Cell A1 = 1, I click a button and the userform brings up Photo1.jpg and shows a picture of a flower

When Cell A1=5, the userform brings up Photo5.jpg and shows a picture of a lion

Any answers are much appreciated.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I believe I am close with this

UserForm1.Image1.Picture = LoadPicture("C:\Users\mambr\OneDrive\Documents\Owen Game\Picture" & "Range("C5").Value" & ".jpg")

but part of this must be off. It works if I simply use the full path, but not with trying to do the variable
 
Upvote 0
The range portion seems off. It's not tied to a worksheet and it's in quotes. I'd try to change that part to

VBA Code:
Application.thisworkbook.worksheets("SheetName").cells(5,3).value
 
Upvote 0

Forum statistics

Threads
1,215,161
Messages
6,123,378
Members
449,097
Latest member
Jabe

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