+ Reply to Thread
Results 1 to 11 of 11

Select Empty Text Boxes

  1. #1
    Registered User
    Join Date
    04-21-2014
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2013
    Posts
    7

    Post Select Empty Text Boxes

    Hi,

    I have files where empty textboxes have been copied over tens if not hundreds of times, thereby slowing down the scrolling speed immensely.

    I would be interested if there was a macro to

    a) select all empty text boxes

    b) select and delete all empty text boxes

    thanks,
    clint

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Select Empty Text Boxes

    Try this, once for each sheet.

    Please Login or Register  to view this content.
    Martin

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Select Empty Text Boxes

    Hi Clint,

    This code will delete or count all the empty text boxes in a workbook. The macro must reside in the workbook that will have 'Text Boxes' deleted.

    Lewis

    Please Login or Register  to view this content.
    Last edited by LJMetzger; 04-22-2014 at 04:09 PM. Reason: Added check for 'Linked Cells' in code.

  4. #4
    Registered User
    Join Date
    04-21-2014
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2013
    Posts
    7

    Thumbs up Re: Select Empty Text Boxes

    @Martin,

    That is brilliant. That is exactly wanted to accomplish. Thanks for the quick and efficient solution.

    @Lewis

    Thank you also for your quick response. However I was not able to get the code to work. I am a novice at Macros admittedly so I may have not executed the code correctly. I just go into the VBA Editor (Alt + F11) choose Insert>Module and then run the macro on each page. Suggestions?

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Select Empty Text Boxes

    You are correct.

    1. Alt F11 to go to the VBA Editor.
    2. If you don't see the project Tree - press 'CTRL R'.
    3.You should see 'ThisWorkbook' under your Excel File Name. If you don't keep on clicking on '+' signs until you do.
    4. Insert > Module (should get you Module 1).
    5. Cut and paste the macros into Module 1.
    6. There are two macros, that act on the entire WORKBOOK, not just one sheet. Select the one you want and run it:
    a. CountActiveXTextBoxesInWorkbook()
    b. RemoveActiveXTextBoxesFromWorkbook()

    I hope this helps.

    Lewis

  6. #6
    Registered User
    Join Date
    04-21-2014
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Select Empty Text Boxes

    Hi Lewis,

    Thanks for your reply. However I fear that I am still doing something wrong. I am attaching a simple workbook that only includes blank text boxes. I pasted in the macro as you described [I think] and the result returns that there are no empty text boxes although I know there are 5-6.

    -clint

    PS - if I look at the code in the first post the "if" statement is looking for a value of " ". Again I am a way out of my league here but is the value in your code looking for " " or zero "0"?
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Select Empty Text Boxes

    Hi Clint,

    Thanks for sticking with me. You did nothing wrong. There are two types of 'Text Boxes':
    a. Active X
    b. Forms

    The code you tested was for the 'Active X' type.
    Attached is code for the 'Forms' type, which you are using. That's why it's always good to post a sample workbook, so that code can be tested on your data.

    In response to your question:
    is the value in your code looking for " " or zero "0"?
    Neither.
    Please Login or Register  to view this content.
    a. The of contents of the 'Text Box' is being read as text.
    b. Leading and trailing spaces are removed using the 'Trim' function.
    c. The length of variable 'sText' is being tested for being length 0 (= no text).

    Lewis

    Code follows:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-21-2014
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2013
    Posts
    7

    Thumbs up Re: Select Empty Text Boxes

    Hi Lewis,

    That is pretty slick. Based on your counter I had +1200 empty text boxes in my file (I had several copies of the same page)

    However there is one item I may have neglected to note. Sometimes I will reference the contents of a cell so they display in the text box. I don't want these to be deleted. In the first solution provided these text boxes are NOT deleted.

    Please Login or Register  to view this content.
    However the code you provided does erase them. Is there a quick way to fix? If not no worries, you've been very helpful already.

    -clint
    ps - you are right I should have included an example from the start. Duly noted for next go around.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Select Empty Text Boxes

    Hi Clint,

    I never knew you could put a formula in a TextBox on a Worksheet. I would not have figured out how to do it without your sample worksheet.

    Try the updated file which deletes a text box if it:
    a. Contains no text AND
    b. Contains no formula

    Lewis

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    04-21-2014
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2013
    Posts
    7

    Thumbs up Re: Select Empty Text Boxes

    Hi Lewis,

    That is amazing - works perfectly. The file is so much quicker to navigate through now. Thanks for your help.

    -clint

    PS - the text box formula comes in handy when you want to automatically update text on a chart. I just write a big formula joining cell references & text strings in quotes in one cell and then reference that cell with the text box. This way at month end I rarely have to update the notes on charts...its done automatically

  11. #11
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Select Empty Text Boxes

    Hi Clint,

    It took a while, but I'm glad it finally worked out for you.

    That is really a great tip about the 'Text Box' formulas. Thanks.

    Lewis

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to select all shapes (text boxes) in workbook
    By Humahuaca in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-21-2012, 12:27 PM
  2. verifying multiple text boxes are not empty
    By h_aesa1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-14-2009, 11:07 AM
  3. check if multiple text boxes are empty
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-17-2009, 09:37 PM
  4. How to select text boxes that are in graphs
    By AussieExcelUser in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 12-12-2007, 11:23 PM
  5. [SOLVED] How to select all hidden text boxes
    By Manish M Kankaria in forum Excel General
    Replies: 2
    Last Post: 01-12-2006, 05:55 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1