Consulting

Results 1 to 2 of 2

Thread: Clear .jpeg in a specific range

  1. #1
    VBAX Regular
    Joined
    Oct 2010
    Location
    Texas
    Posts
    93
    Location

    Clear .jpeg in a specific range

    Hello Everyone,

    I'm trying to clear a .jpeg from a specific range on a worksheet. A VBAX member was kind enough to provide me with the code shown below. It does a great job but it does delete all of the pics on the spreadsheet. Can it be modified so that only the .jpeg in the specified range gets cleared? I tried to modify it without success.

    I appreciate your help!!

    Sub Proc2()
    ' Remove pictures
    Dim DrObj
    Dim Pict
    Set DrObj = wksWHMaster.DrawingObjects
    For Each Pict In DrObj
    If Left(Pict.Name, 7) = "Picture" Then
    Pict.Select
    Pict.Delete
    End If
    Next
    End Sub

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    Assuming that wksWHMaster is a sheet,

    [vba]Sub blah()
    For Each Pict In wksWHMaster.Pictures
    If TypeName(Pict) = "Picture" Then Pict.Select
    Next
    End Sub
    [/vba] may work for you and is a bit tidier.
    Now as to deleting a picture to be found on a range in a worksheet, each picture has a topleftcell and a bottomrightcell viz.:

    [vba]Sub blaha()
    For Each Pict In wksWHMaster.Pictures
    If TypeName(Pict) = "Picture" Then
    ' MsgBox Pict.TopLeftCell.Address
    ' MsgBox Pict.BottomRightCell.Address
    If Not Intersect(Pict.TopLeftCell, Range("I19:J20")) Is Nothing Then
    Pict.Select
    'Pict.delete
    End If
    End If
    Next
    End Sub[/vba]
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •