+ Reply to Thread
Results 1 to 10 of 10

Code to add text to a cell that is left blank after a VBA form has been filled in.

  1. #1
    Registered User
    Join Date
    09-11-2019
    Location
    Canada
    MS-Off Ver
    2010, Excel 365
    Posts
    27

    Code to add text to a cell that is left blank after a VBA form has been filled in.

    Hi All,

    I have a VBA form which is complete, except for 1 code that I cannot get to work, basically when a user completes the form it enters the information in to the data sheet, but if the user leaves a cell on the form blank (may come back to update the cell at a leter date) i need a code that would insert "MISSING" into the cell, I used the following code which works but it overwrites the users input if they do add text to the cell when completing the form, CODE as follows;

    Worksheets("TRAINING DATABASE").Cells(lastrow + 1, 2).Value = "MISSING"

    The next following code puts the users input into the cell;

    Worksheets("TRAINING DATABASE").Cells(lastrow + 1, 2).Value = TextBox2.Text

    I have tried using various ways of doing this, one way was using 'Then' and/or 'IF' statement but i keep getting an error using 'Then' and/or 'IF'! any body have any ideas on how to use this code so that if the user inputs text it doesnt overwrite the users input and if the user does not enter code then it will enter "MISSING"

    I appreciate all help on this matter

    (please note i have tried to upload a small spreadsheet for viewing etc but I keep getting a error code on the upload page, maybe due to the ongoing site update.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Code to add text to a cell that is left blank after a VBA form has been filled in.

    Is the form just adding records to the next blank row or are you also using it to update previously submitted rows? i.e. not necessarily the last row of data?

    Ignore the attached file. I'm just attaching a blank file to test if I get an error when uploading.

    BSB
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    09-11-2019
    Location
    Canada
    MS-Off Ver
    2010, Excel 365
    Posts
    27

    Re: Code to add text to a cell that is left blank after a VBA form has been filled in.

    Hi and thanks BadlyspeleedBuoy for the quick reply there is two command buttons one to add new data to the next row and another command button to update any row that has a id number. I have posted small sections of each VBA command the list is short but it does go to textbox66;

    Please Login or Register  to view this content.
    Again thanks for any help.

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Code to add text to a cell that is left blank after a VBA form has been filled in.

    So, let me just get this straight in my mind, if a control on the form is left blank when submitting a new row of data it should put "missing".
    If a record (row of data) is being updated it should overwrite if it says missing, but leave the value as is IF control was left blank but the corresponding cell on the worksheet already has a value other than "missing"??

    It would really help if you could try again to attach your file. Looking at your code above we could really help tidy that up if we could see it in context.
    For example, looping through the form controltls rather than having a line of code for each.

    BSB

  5. #5
    Registered User
    Join Date
    09-11-2019
    Location
    Canada
    MS-Off Ver
    2010, Excel 365
    Posts
    27

    Re: Code to add text to a cell that is left blank after a VBA form has been filled in.

    So hopefully this upload works, fingers crossed.

    Hi BSB, I have condensed the worksheet as best as possible, and yes to your question, I have added the comments below to the spreadsheet so that you can see what im trying to achieve, again thanks for your time and help.

    AFTER USER HAS
    FINISHED FILLING IN THE FORM AND DATA HAS BEEN ENTERED INTO THIS SPREADSHEET IF ANY CELL IS BLANK THEN A CODE FROM THE VBA FORM WILL ENTER "MISSING" INTO THE BLANK CELLS,
    UNTIL THE USER COMES BACK AT A LATER DATE AND THEN EITHER USES THE FORM TO UPDATE OR MANUALLY UPDATES THE "MISSING" CELLS WITH THE NEW INFORMATION .

    ALTHOUGH THIS IS A CONDENSED VERSION ENTRIES WILL BE OVER THE 2000 PLUS ROW RANGE SO THE REASON FOR THE "MISSING" IS SO THAT THE BLANK CELLS WILL NOT BE FORGOTTEN ABOUT
    Attached Files Attached Files

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Code to add text to a cell that is left blank after a VBA form has been filled in.

    OK, in the attached version of your file what I've done is add a number to the "Tag" property of all the Combo & Text boxes on your form that corresponds to the column number the data should be stamped to.
    That will allow you to loop through the controls and use that tag value rather than have to have a line of code for each control.

    This is the revised code for your "add new" button. It will stamp a new record to the end of the data and any blank controls will be stamped as "MISSING".
    Please Login or Register  to view this content.

    BSB
    Attached Files Attached Files

  7. #7
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Code to add text to a cell that is left blank after a VBA form has been filled in.

    I've also revised the code for the "update" button. IT will find the row to update based on the customer ID entered.
    If any controls are left blank it will stamp them as missing, unless there's already a value recorded in the data for that column.
    If the column says missing it will be overwritten by the value entered on the form.

    For some reason the forum won't let that part of the code paste and just gives me a blank screen when I try.

    Give it a try and let me know if it does what you need.

    BSB

  8. #8
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Code to add text to a cell that is left blank after a VBA form has been filled in.

    Hmmm. Seems to let me add that bit of the code when I don't include my explanation with it.

    Please Login or Register  to view this content.
    BSB

  9. #9
    Registered User
    Join Date
    09-11-2019
    Location
    Canada
    MS-Off Ver
    2010, Excel 365
    Posts
    27

    Re: Code to add text to a cell that is left blank after a VBA form has been filled in.

    My hat goes off to you sir ......again I thank you for your time and help, your code works perfectly, I tried adding reputation but its not letting me? will keep at it though, but thanks anyway you are very much appreciated.

  10. #10
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Code to add text to a cell that is left blank after a VBA form has been filled in.

    Very happy I could help And hopefully the revised code will save you wearing your fingers out writing all that code using your original approach

    BSB

+ 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. [SOLVED] Function to move text data to left blank cell
    By Karnik in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-12-2016, 08:03 PM
  2. [SOLVED] Need a code: if the line on collum on left is filled with some value, this collumn
    By coringa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-04-2016, 04:09 PM
  3. Add row with formatting if text in cell OR add blank row filled with blue if blank
    By sierradk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2014, 04:15 AM
  4. VBA code that adds comment to cell by userform; runtime error 1004 when left blank
    By dmbroekhuysen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-26-2014, 01:02 PM
  5. [SOLVED] Copy and paste values if cell to the left is filled
    By skip2mylew in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-04-2013, 08:54 PM
  6. Vlookup only until the cell on the left is filled
    By movielux in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2012, 07:36 AM
  7. Code error in blank text boxes checking and saving in user form
    By jwala in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-03-2010, 08:19 AM

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