Excel Macro to Insert Picture: Help cleaning up code to

Tele720

New Member
Joined
Aug 20, 2007
Messages
10
I have a macro that works well to insert multiple pictures into multiple different locations from a specified directory, but it seems to run a little slow. (I've noticed a difference between Excel2003 and Excel2010).

Below is a portion of the code for one of the 1st loops, but I am specifically wondering about the following bit:

Code:
Cells(sr_offset + 21 * i, sc_offset + 11 * j).Select
ActiveSheet.Pictures.Insert(SEM_dir & "\" & RUN_dir & "\" & SEM_pic & ".jpg").Select

I feel like there is a cleaner more efficient way to do this than using the "Select". Any help would be greatly appreciated as well as confirmation that this is the most efficient way to accomplish inserting the picture.

Code:
Private Sub InsertSEM_Click()
' InsertSEM Macro

' Dimension variables
    Dim SEM_dir As String
    Dim RUN_dir As String
    Dim SEM_pic As String
    Dim row_offset As Integer
    Dim col_offset As Integer
    Dim sr_offset As Integer
    Dim sc_offset As Integer
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim PicMsg As String
           
' Specifying variables
    SEM_dir = Cells(3, 7).Value
    RUN_dir = Cells(4, 7).Value
    row_offset = 6
    
    On Error GoTo line140
    
' Inserting SEM Pictures
'   Inserts Page 1 Center SEM Pics
    col_offset = 2
    For i = 1 To 2 Step 1
        For j = 1 To 2 Step 1
        If Cells(row_offset + i, col_offset + j).Value = Empty Then
            GoTo line80
        Else
            SEM_pic = Cells(row_offset + i, col_offset + j).Value
            sr_offset = 25
            sc_offset = -9
            Cells(sr_offset + 21 * i, sc_offset + 11 * j).Select
            ActiveSheet.Pictures.Insert(SEM_dir & "\" & RUN_dir & "\" & SEM_pic & ".jpg").Select
        End If
line80:
        Next j
    Next i
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,224,574
Messages
6,179,628
Members
452,933
Latest member
patv

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