• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How do I get rid of all TextBoxes in Excel via VBA (empty)

madocar

Member
Hello,

please is there any way how do I get rid of all TextBoxes in active sheet that are EMPTY via VBA?
There's a ton of them and my Excel got frozen.

Thank you for any help
 
Hello Madocor

You can use the following VBA code to delete all empty TextBoxes on the active sheet:

Code:
Sub RemoveEmptyTextBoxes()
    Dim shp As Shape
    
    ' Loop through all shapes in the active sheet
    For Each shp In ActiveSheet.Shapes
        ' Check if the shape is a TextBox and if its text is empty
        If shp.Type = msoTextBox And shp.TextFrame.Characters.Text = "" Then
            ' Delete the TextBox
            shp.Delete
        End If
    Next shp
End Sub
 
Hello @Monty

thank you for your quick answer.
Now I get this error:


1705433990281.png


Is there any way how to fix this?

Thank you very much Monty in advance
 
Hello, according to your guessing challenge :rolleyes: maybe via splitting the If in two Ifs …​
 
so instead of AND use two IF functions?
how would it look like the whole code?

thank you in advance
 
Try
Code:
Sub belle()
Dim oTextBox As TextBox
For Each oTextBox In ActiveSheet.TextBoxes
    If oTextBox.Characters.Count = 0 Then oTextBox.Delete
Next oTextBox
End Sub
 
Back
Top