+ Reply to Thread
Results 1 to 10 of 10

Using InputBox to clear information in a cell

  1. #1
    Forum Contributor
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    Version 14.4.3, Mac 2011
    Posts
    145

    Question Using InputBox to clear information in a cell

    This is long but interesting and was fun to work on!

    Background
    So I've been working on a macro that allows me to efficiently preview/edit the sources for a sheet of data by displaying the information listed in a second almost identical sheet that contains only sources, using either a MsgBox or InputBox.

    The macro is run by making a selection of either a single cell or a range of cells on the first sheet ('Data') and clicking a button to bring up the appropriate box with the value of the same cell on the second sheet ('Source').

    Summary of Macro Function:
    What happens when a user selects data?
    If selecting a single empty cell, shows a message box that reads please select a cell with data.
    If selecting a range of empty cells, shows as above.
    If selecting a single cell of data, shows an input box with current source value as default and the ability to edit.
    If selecting a range of cells that are all blank except one, treats as if selecting a single cell.
    If selecting a range of cells that have multiple values of data, returns message box of sources, no edit capability.
    Range of cells skip blank data cells.

    The Issue
    I noticed that with my current code, if I select a single cell, try to delete the default input box value, and press OK, the action is rendered useless and the current value remains in the 'Sources' Sheet. This is the result of me trying to make the Cancel button not delete the default value.

    If I enter a single space, conditional formatting, which runs off ISBLANK, does not highlight the now sourceless Data. This is because the cell is not effectively blank. I believe the solution is the ability to set the Source cell value back to default when input box is empty and OK is clicked.

    Do you guys have any thoughts?

    Code attached below with a ton of comments! (feel free to point out where I'm stupid, started VBA a little while ago)

    :D

    Red

    Please Login or Register  to view this content.
    Last edited by RedSummer; 04-16-2015 at 09:16 PM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Using InputBox to clear information in a cell

    Attaching a sample workbook enables others to work on your problem:

    To attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  3. #3
    Forum Contributor
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    Version 14.4.3, Mac 2011
    Posts
    145

    Re: Using InputBox to clear information in a cell

    Thanks davesexcel,
    Attached please find my workbook. The module holds the previous 2 source macros but v3 is the one I'm working on.

    Excel Source Macro Test.xlsm

    Again, new to VBA but I commented as best I could to explain what I was doing. There may be easier ways. Thanks for taking a look whoever you are!

  4. #4
    Forum Contributor
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    Version 14.4.3, Mac 2011
    Posts
    145

    Re: Using InputBox to clear information in a cell

    It's really not that intimidating, the workbook macro button is pretty fun to use, I just need to figure out how an empty input box can be used to delete cell content even if I have the following:

    Please Login or Register  to view this content.
    Please download my workbook :D

  5. #5
    Forum Contributor
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    Version 14.4.3, Mac 2011
    Posts
    145

    Re: Using InputBox to clear information in a cell

    Bump no response

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Using InputBox to clear information in a cell

    You may use this:
    Please Login or Register  to view this content.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  7. #7
    Forum Contributor
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    Version 14.4.3, Mac 2011
    Posts
    145

    Re: Using InputBox to clear information in a cell

    Thank you very much for your reply Izandol.
    It works magnificently, I'm such a VBA noob that I was wondering if you can explain the major difference between these two functions?
    Please Login or Register  to view this content.
    Because I'm starting to think if I only include your function I will be able to delete the one above with vbNullString.

  8. #8
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Using InputBox to clear information in a cell

    You do not need to use vbNullString test also - only StrPtr test.

    vbNullString is constant representing a null string - a null pointer. That is not same as empty string ("") but VBA will treat as equal if you compare them. If you will press Cancel on inputbox, null string is returned. If you press OK but do not enter any data, empty string is returned. To make difference between these two we must test if the pointer is null with StrPtr - this will only be true for null string, not empty string. I hope you can understand my meaning because this is not so easy idea!

  9. #9
    Forum Contributor
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    Version 14.4.3, Mac 2011
    Posts
    145

    Re: Using InputBox to clear information in a cell

    Wow yes a little confusing but I think understand that vbNullString will not differentiate between the pointer and the string but StrPtr will?

    I am running into an issue with my code, when I select one cell and edit ("" -> OK) there is no problem but when I select a range with a blank cell and 1 cell with data the input box does not behave the same way.

    Please Login or Register  to view this content.
    Excel Source Macro Test.xlsm
    Here is the updated sheet to test, the BOTTOM button is the one that runs the above macro.
    I think it might have to do with my ws2save variable that I made because I couldn't use ws2.Range(cell.Address) without defining cell again (which I don't know how to do without the loop).

  10. #10
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Using InputBox to clear information in a cell

    I do not understand what you want to do. May you please explain exactly? It can be that you only need ws2.Range(ws2save)

+ 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. VBA code to clear the contents (or value) of a cell without clearing the formula
    By BazzaBit in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-10-2013, 08:16 PM
  2. [SOLVED] Inputbox to code for input text in cells.
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-07-2013, 12:24 PM
  3. How to clear formula without clearing cell contents
    By prayami in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-03-2008, 04:33 AM
  4. [SOLVED] Clear a worksheet without clearing formulas?
    By doodah in forum Excel General
    Replies: 4
    Last Post: 01-02-2006, 04:59 PM
  5. [SOLVED] How do I clear a column of data without clearing the formulas?
    By EllenSwarts in forum Excel General
    Replies: 2
    Last Post: 03-11-2005, 11:06 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