VBA Loop Though Column of Data, Select Shape in offset column

dcoker

New Member
Joined
Dec 13, 2018
Messages
36
Hi.

I'm trying to figure out how to loop through column "I"
If it finds a cell that is blank, skip the row, move to next row until it finds a cell containing a value
Once it finds a cell with a value in column "I", select the picture in column "B" of the same row.

Once the picture is selected, export the picture.

Any help is appreciated!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
For FIRST test
- create a NEW test folder to export the images (to prevent overwriting anything)
- Place code in a new module
- Amend ONLY image export path "C:\Test\imagesFolder"
- Run code from sheet containing the images

Come back if you require further help

VBA Code:
Sub ExportImages()
    Dim shp As Shape
    For Each shp In ActiveSheet.Shapes
        If shp.Type = msoPicture Then
            With shp.TopLeftCell
                If .Column = 2 And .Offset(, 7) <> "" Then Call ExportPicture(shp)
            End With
        End If
    Next shp
End Sub
    
Private Sub ExportPicture(pic As Shape)
    Const picPath = "C:\Test\imagesFolder"
    pic.Copy
    With ActiveSheet.ChartObjects.Add(0, 0, pic.Width, pic.Height)
        .Chart.ChartArea.Select
        .Chart.Paste
        .Chart.Export picPath & "\" & pic.Name & ".jpg"
        .Delete
    End With
End Sub
 
Upvote 0
For FIRST test
- create a NEW test folder to export the images (to prevent overwriting anything)
- Place code in a new module
- Amend ONLY image export path "C:\Test\imagesFolder"
- Run code from sheet containing the images

Come back if you require further help

VBA Code:
Sub ExportImages()
    Dim shp As Shape
    For Each shp In ActiveSheet.Shapes
        If shp.Type = msoPicture Then
            With shp.TopLeftCell
                If .Column = 2 And .Offset(, 7) <> "" Then Call ExportPicture(shp)
            End With
        End If
    Next shp
End Sub
   
Private Sub ExportPicture(pic As Shape)
    Const picPath = "C:\Test\imagesFolder"
    pic.Copy
    With ActiveSheet.ChartObjects.Add(0, 0, pic.Width, pic.Height)
        .Chart.ChartArea.Select
        .Chart.Paste
        .Chart.Export picPath & "\" & pic.Name & ".jpg"
        .Delete
    End With
End Sub


That seems to work for the most part so far!
How / Where would I assign column "I" value as the new file name?
Thanks!
 
Upvote 0
I think I figured it out by adding the code below

VBA Code:
'
shpfname = .Offset(, 7)
If .Column = 2 And .Offset(, 7) <> "" Then Call ExportPicture(shp, shpfname)

'

'

Private Sub ExportPicture(pic As Shape, shpfname As String)

'

.Chart.Export picPath & Left(shpfname, Len(shpfname) - 4) & "_thumb.jpg"
 
Upvote 0
your code in post#4 above suggests you are on the right track (y)
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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