+ Reply to Thread
Results 1 to 7 of 7

Thread: How can I clear cells that have focus if value is "#N/A"?

  1. #1
    Registered User
    Join Date
    01-17-2012
    Location
    Pacific Northwest
    MS-Off Ver
    Excel 10
    Posts
    34

    Question How can I clear cells that have focus if value is "#N/A"?

    SOLVED I'm using combo boxes linked to tables to fill their respective lists. If an item is on the list the Table lookups fill in most of the remaining cells automatically. If the item is NOT on the list the Table lookups return "#N/A" instead of Item Description and Price. I would like clear the values of those cell so that new values can be entered into those cells.

    Your help is appreciated!
    Last edited by TMShucks; 02-05-2012 at 06:06 PM. Reason: User requested mark Solved

  2. #2
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    825

    Re: How can I clear cells that have focus if value is "#N/A"?

    as an option
    Sub Button1_Click()
    [a:c].Replace "#N/A", "", xlWhole  'change range for yr needs
    End Sub
    Regards, John

  3. #3
    Registered User
    Join Date
    01-17-2012
    Location
    Pacific Northwest
    MS-Off Ver
    Excel 10
    Posts
    34

    Re: How can I clear cells that have focus if value is "#N/A"?

    In the long run, I'd prefer not to have to add a special button just to clear a few boxes if it could be avoided but as a learning experience, I gave it a try. The first thing I noticed was that unlike my combo boxes, the command button is not listed in the dropdown when going back the code for my sheet. The next thing I noticed was that I couldn't pull up a properties list for my new command button. At that point I decided to try to get creative and see if I could use it in the LostFocus routine of my combo box.
    Private Sub cbxItems_LostFocus()
    Range("D12").Replace Chr(34) & "#N/A" & Chr(34), "", xlWhole
    End Sub
    I'm not familiar with "Replace" or "xlWhole" so none of my variations returned anything but "Reference Not Valid" errors.
    ie.
    Range(D12).Replace Chr(34) & "#N/A" & Chr(34), "", xlWhole
    D12.Replace Chr(34) & "#N/A" & Chr(34), "", xlWhole
    "D12".Replace Chr(34) & "#N/A" & Chr(34), "", xlWhole
    (D12).Replace Chr(34) & "#N/A" & Chr(34), "", xlWhole

  4. #4
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    825

    Re: How can I clear cells that have focus if value is "#N/A"?

    try it in worksheet event
    if you have #N/A in that range it'll be replaced ...with nothing!

    Private Sub Worksheet_Change(ByVal Target As Range)
    [a:c].Replace "#N/A", "", xlWhole  'change range for yr needs
    End Sub
    Attached Files Attached Files
    Regards, John

  5. #5
    Registered User
    Join Date
    01-17-2012
    Location
    Pacific Northwest
    MS-Off Ver
    Excel 10
    Posts
    34

    Re: How can I clear cells that have focus if value is "#N/A"?

    Thanks John! I see that it was a mistake to take the brackets to mean [insert your range here]. I was so caught up in trying to find a working syntax for a single cell at a time and it proved to be so much more elegant than that!
    Thank YOU!

  6. #6
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    825

    Re: How can I clear cells that have focus if value is "#N/A"?

    Glad it helped you!
    thx!

    If your problem is solved, please say so clearly, and mark your thread as Solved:
    Click the Edit button on your first post in the thread,
    Click Go Advanced,
    select [SOLVED] from the Prefix dropdown,
    then click Save Changes.
    Regards, John

  7. #7
    Registered User
    Join Date
    01-17-2012
    Location
    Pacific Northwest
    MS-Off Ver
    Excel 10
    Posts
    34

    Re: How can I clear cells that have focus if value is "#N/A"?

    Thanks for the instructions, I *thought* the Star was selected to mark it as "solved".
    I appreciate it! Went to Advanced and did not see anything indicating "Solved". Please let me know if there's anything more I can do to ensure that you get credit for your time and effort.
    Last edited by imaquila; 02-05-2012 at 12:34 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0