• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

How do I delete images in a specific range|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / How do I delete images in a specific range|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosHow do I delete images in a specifi…
sp_PrintTopic sp_TopicIcon
How do I delete images in a specific range
Avatar
Milena Stevanov

New Member
Members
Level 0
Forum Posts: 2
Member Since:
May 5, 2018
sp_UserOfflineSmall Offline
1
May 5, 2018 - 5:13 am
sp_Permalink sp_Print
I have a macro that imports data from a selected file. The data includes some images. The problem I am having is if i have data and images already in my document, and I go to import new data, the images do not delete and simply get pasted on top of each other. I wrote code to select the cells and clear them, but it doesn't clear the images.

I think the solution is to put some code at the beginning that can select the images in the cell range and delete them, before the new data is imported.

I came across a solution that Selects all images in the worksheet and deletes them, But I have other images that I need to keep.

Is is possible to tell it to select all images in a specific range of cells?

sp_AnswersTopicSeeAnswer See Answer
Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
2
May 5, 2018 - 10:15 am
sp_Permalink sp_Print

Hi Milena

Welcome to the forum.

Just select the required range and then run the macro below.

Sub DeletePictures()
Dim Sh As Shape
For Each Sh In ActiveSheet.Shapes
If Not Application.Intersect(Sh.TopLeftCell, Range(Selection.Address)) Is Nothing Then
Sh.Delete
End If
Next Sh
End Sub

Hope this helps.

Sunny

sp_AnswersTopicAnswer
Answers Post
Avatar
Milena Stevanov

New Member
Members
Level 0
Forum Posts: 2
Member Since:
May 5, 2018
sp_UserOfflineSmall Offline
3
May 8, 2018 - 12:16 am
sp_Permalink sp_Print sp_EditHistory

Thank you! The Code that ended up working is this

 

Sub DeleteImage() Dim pic As Picture ActiveSheet.Unprotect For Each pic In ActiveSheet.Pictures If Not Application.Intersect(pic.TopLeftCell, range("H10:R24")) Is Nothing Then pic.Delete End If Next pic End Sub
Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
4
May 8, 2018 - 10:47 am
sp_Permalink sp_Print

Hi Milena

Glad to know you got it solved.

Sunny

Avatar
tolu adeogba

New Member
Members
Level 0
Forum Posts: 1
Member Since:
January 19, 2019
sp_UserOfflineSmall Offline
5
January 19, 2019 - 1:54 am
sp_Permalink sp_Print

Hi

i Tried the exact code and it does nothing for me. idk if its because of my image format (GIF)

 

Sheets("Print PG").Select
Dim pic As Picture
For Each pic In ActiveSheet.Pictures
If Not Intersect(pic.TopLeftCell, Range("A85:K101")) Is Nothing Then
pic.Delete
End If

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
6
January 20, 2019 - 3:00 am
sp_Permalink sp_Print

Hi Tolu

Your codes looks incomplete.

Both Milena's and my codes work on GIF as well.

Make sure that the images are inside the range you specified.

Why don't you copy our codes and retry again.

Sunny

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Rocco Pinneri, Alexandra Radu, AndyC
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Raj Mattoo
Mark Luke
terimeri dooriyan
Jack Aston
AndyC
Denise Lloyd
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Forum Stats:
Groups: 3
Forums: 24
Topics: 6219
Posts: 27276

 

Member Stats:
Guest Posters: 49
Members: 31903
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.