Excel VBA for selecting / deletion of only line type objects in a specified range

LBicker

New Member
Joined
Feb 26, 2013
Messages
19
I have a very complex worksheet which currently writes lines and text boxes (by VBA) overtop / underneath a transparent graph.
When updating these lines / text boxes, I must start by removing all previous.
All was working fine until excel 2010 was installed. (previously 2003)
Here is the sample of the previous deletion code.
It is important that only lines and text boxes be deleted. (the graph must remain intact)
Thanks to all

Private Sub SheetObjDel()
Dim intObj As Long
Dim i As Long
Dim tmp As String
Dim exist_cnt As Long

exist_cnt = 0

intObj = ActiveSheet.Shapes.Count
Range("A1").Activate

For i = 1 To intObj
obName = ActiveSheet.Shapes(i).Name
If ActiveSheet.Shapes(i).Top > ActiveSheet.Range("I8").Top Then
ActiveSheet.Shapes(i).Select False
exist_cnt = exist_cnt + 1
End If
Next i

If exist_cnt > 0 Then
Selection.Delete
End If

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Do you get an error in 2010 or nothing happens in 2010? Have you stepped through the code to see if shapes are being selected?
 
Upvote 0
50/50%
And, yes.
It tries to select and delete more than lines / text boxes and tnen subsequently crashes.
Also, the previously working code for object selection & deletion now takes ~ 5 minutes to work as opposed to 10 secs.

If this information helps, I have renamed the file to be ****.xlsm type format
 
Upvote 0
50/50%
And, yes.
It tries to select and delete more than lines / text boxes and tnen subsequently crashes.
Also, the previously working code for object selection & deletion now takes ~ 5 minutes to work as opposed to 10 secs.

If this information helps, I have renamed the file to be ****.xlsm type format
Are the things beyond lines/text boxes it tries to delete shape objects or something else?

If you try on a copy of your sheet:
Activesheet.Shapes.SelectAll
does that select all shapes?
 
Upvote 0
Not sure exactly what it is "hitting"
There are literally 14,000+ lines to delete at a time.
My computer usually freezes and excel crashes before I get a chance to troubleshoot.
I have attempted using this code.
Activesheet.Shapes.SelectAll
Unfortunately all items, transparent graph and other shapes need to be excluded except in a range below row #8.
Do you know a way to modify, the existing code I provided to group select between rows #8 and lower (ever growing & shrinking in # of used rows)?

Thanks

Additionally, the only error I get is after "restarting" excel 2010, that message is this:
Run-Time error '1004'
Unable to get the Top property of Range class
 
Last edited:
Upvote 0
Your code appears to select, properly, only those shapes whose tops are below row 8.

Wish I could be more help, but there is nothing I can see in the code that would prevent it running any less effectively in Excel 2010 than in Excel 2003.
 
Upvote 0
Your code appears to select, properly, only those shapes whose tops are below row 8.

Wish I could be more help, but there is nothing I can see in the code that would prevent it running any less effectively in Excel 2010 than in Excel 2003.
Many thanks for your consideration.
Here's hoping someone else might have an idea.
 
Upvote 0
correct or not.
I ended up modifying to read:
Private Sub SheetObjDel()
Dim intObj As Long
Dim i As Long
Dim tmp As String
Dim exist_cnt As Long

exist_cnt = 0

ActiveSheet.Lines.Select
Selection.delete

intObj = ActiveSheet.Shapes.Count
Range("A1").Activate

For i = 1 To intObj
obName = ActiveSheet.Shapes(i).Name
If ActiveSheet.Shapes(i).Top > ActiveSheet.Range("I8").Top Then
ActiveSheet.Shapes(i).Select False
exist_cnt = exist_cnt + 1
End If
Next i

If exist_cnt > 0 Then
Selection.Delete
End If

End Sub

This works for me until some other issue comes up.
Like lines which cannot / should not be deleted.
It would be best to only select all lines (at once) if below range("I8") but I do not know how...
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,443
Members
448,898
Latest member
drewmorgan128

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