PDA

View Full Version : Solved: Clear .Jpeg



chem101
10-19-2010, 05:39 AM
Hello Everyone,

I need your help. I'm able to import a .jpeg picture into a spreadsheet. I can then copy it to another spreadsheet in the same workbook. I can do both using VBA code. The problem I'm having is using code to clear the picture on the user form. This is what I've tried so far:

Sub ClearInputs()
With wksNewOrder
.Range("i33:aa44").ClearContents
End With
End Sub


I've also tried:

Sub NewOrderClearInputs()
Application.ScreenUpdating = False
Range("c8:c8").Select
Selection.ClearContents
End Sub

I feel like there's a simple solution that I'm just not seeing. I don't think I'm calling out the pic correctly in the code.

Any assistance you can provide will be greatly appreciated!

Thank you!

softman
10-19-2010, 06:17 AM
I am using this code, but remember it will remove all the pictures:

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

chem101
10-19-2010, 06:48 AM
Works Great!!

Thank you very much!!

chem101
10-19-2010, 06:50 AM
Can the code be altered so that only pictures in a certain range on the worksheet are cleared?

Thank you!!

chem101
10-19-2010, 06:53 AM
I am using this code, but remember it will remove all the pictures:

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


Can the code be altered so that it clears a .jpeg only in a designated range on the worksheet?

Thank you!!

softman
10-28-2010, 03:27 AM
Hi Chem101,

Here is the solution you are looking for removing pictures in a range:

Sub Proc2()
Dim s As String
Dim pic As Picture
Dim rng As Range
' Set ws = ActiveSheet
Set ws = ActiveWorkbook.Worksheets("Pixtures")
Set rng = ws.Range("A6:O145")
For Each pic In ws.Pictures
With pic
s = .TopLeftCell.Address & ":" & .BottomRightCell.Address
End With
If Not Intersect(rng, ws.Range(s)) Is Nothing Then
pic.Delete
End If
Next
End Sub

chem101
10-28-2010, 05:34 AM
Thank you very much for your response. The help I've received from you all is greatly appreciated!!