looping through cells

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I wanted to loop through this code :
Code:
Sheet1.Image1. Picture = LoadPicture (fPath & "\" & Sheet1. Range ("B2") & ".jpg")
Sheet1.Image2. Picture = LoadPicture (fPath & "\" & Sheet1. Range ("B12") & ".jpg")
Sheet1.Image3. Picture = LoadPicture (fPath & "\" & Sheet1. Range ("B22") & ".jpg")
........ to 20 controls
So I tried the below:
Code:
For x = 0 To 90 Step 10
For i = 1 To 20
Sheet1.OLEObjects ("Image" & i).Object. Picture = LoadPicture (fPath & "\" & Sheet1. Range ("B" & x + 2) & ".jpg")
Next i
Next x
Then I had some funny results. Only one image filled all the controls. Can somebody pull me out?
Regards
Kelly
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Code:
  For i = 1 To 20
    With Sheet1
      .OLEObjects("Image" & i).Object.Picture = LoadPicture(fPath & "\" & .Cells(10 * i - 8, "B") & ".jpg")
    End With
  Next i
 
Upvote 0
Oh okay thanks
Changed
Code:
LoadPicture(fPath & "" &
To
Code:
LoadPicture(fPath & "\" &
 
Upvote 0
Curious -- the path separator is in my post.
 
Upvote 0
Code:
  For i = 1 To 20
    With Sheet1
      .OLEObjects("Image" & i).Object.Picture = LoadPicture(fPath & "\" & .Cells(10 * i - 8, "B") & ".jpg")
    End With
  Next i

Hello,

I just created a challenge for myself. I have divided the IDs into 2: 10 on column B then another 10 on column F. They are not arranged in any order. They are randomly placed by a lookup formula. I did the division so I can get all 20 on one page when printed.

Is there a way the above can look at both columns ?

Regards
Kelly
 
Upvote 0
Okay I have tried this and it seems to work. If there is a better way let me know. Thanks

Code:
For i = 1 To 20
    With Sheet1
      .OLEObjects("Image" & i).Object.Picture = LoadPicture(fPath & "\" & .Cells(10 * i - 8, "B") & ".jpg")
      .OLEObjects("Image" & i + 10).Object.Picture = LoadPicture(fPath & "\" & .Cells(10 * i - 8, "F") & ".jpg")
    End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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