+ Reply to Thread
Results 1 to 11 of 11

Find first empty cell in column and enter value from textbox

  1. #1
    Registered User
    Join Date
    09-09-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    21

    Find first empty cell in column and enter value from textbox

    I have a textbox in a UserForm that I'm using to add a text str to empty cells in a column. Using the following code:

    Please Login or Register  to view this content.
    I'd like to have excel look for the next empty cell the column. I found, what looks like to me, an elegant solution:

    Please Login or Register  to view this content.
    I'm having trouble combining the codes and this is where I need help.

    Thanks
    Last edited by JBeaucaire; 09-15-2014 at 04:54 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Find first empty cell in column and enter value from textbox

    Something like perhaps:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor Cerbera's Avatar
    Join Date
    07-06-2010
    Location
    Rotorua, New Zealand
    MS-Off Ver
    Excel 2007, 2013, 2016 & 365
    Posts
    137

    Re: Find first empty cell in column and enter value from textbox

    JB's solution is elegant and I'm certain will be that answer that you need, however the one thing I would mention is that it would enter the value in the next empty cell at the bottom of a column of data (ignoring any empty cells interspersed within the data). If you need to find the first empty cell then your piece of code is the one to utilise:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-09-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    21

    Re: Find first empty cell in column and enter value from textbox

    The code returned a value in the columns cells below the selected cell.

    For example:
    c
    co
    col
    colu
    colum
    column

    Private Sub TextBox1_Change()
    Range("A2").End(xlDown).Offset(1, 0).value = TextBox1.value
    ActiveCell.value = TextBox1.Text
    End Sub

  5. #5
    Forum Contributor Cerbera's Avatar
    Join Date
    07-06-2010
    Location
    Rotorua, New Zealand
    MS-Off Ver
    Excel 2007, 2013, 2016 & 365
    Posts
    137

    Re: Find first empty cell in column and enter value from textbox

    Hi Kevin,

    That's the "Offset(1, 0).value" it's finding the last filled cell and then selecting the one below that, which is therefore the next empty cell.

    Were you looking for a different action?

  6. #6
    Registered User
    Join Date
    09-09-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    21

    Re: Find first empty cell in column and enter value from textbox

    Yes, I want to write a person's name in the next empty cell in a column.

  7. #7
    Registered User
    Join Date
    09-09-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    21

    Re: Find first empty cell in column and enter value from textbox

    In this instance I tried getting the word "column" in one cell. Which it did after expending 5 cells above, but I'm asking to fill only one cell with one word. . Some might say I'm too picky, but then I watch my dog search for a place to poop.


    VBAcode.png

  8. #8
    Forum Contributor Cerbera's Avatar
    Join Date
    07-06-2010
    Location
    Rotorua, New Zealand
    MS-Off Ver
    Excel 2007, 2013, 2016 & 365
    Posts
    137

    Re: Find first empty cell in column and enter value from textbox

    Hi Kevin,

    I see what you're doing there and why it's doing what it is.

    You could change the way the input works so that it enters the value in the text box when you click out of it:


    Please Login or Register  to view this content.
    Or you can remove your macro entirely and then add an ActiveX Command Button to the sheet - then right click and select View Code.

    Change the code to:


    Please Login or Register  to view this content.

    Also note that in both examples above you can replace this code:

    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    09-09-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    21

    Re: Find first empty cell in column and enter value from textbox

    These aren't going in the sheet, I'm trying to use them in a userform.

  10. #10
    Registered User
    Join Date
    09-09-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    21

    Re: Find first empty cell in column and enter value from textbox

    The command button was the best solution. Thank you.

  11. #11
    Forum Contributor Cerbera's Avatar
    Join Date
    07-06-2010
    Location
    Rotorua, New Zealand
    MS-Off Ver
    Excel 2007, 2013, 2016 & 365
    Posts
    137

    Re: Find first empty cell in column and enter value from textbox

    Excellent, glad it's sorted and I've learnt a bit myself in the process

  12. #12
    Registered User
    Join Date
    09-09-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    21

    Re: Find first empty cell in column and enter value from textbox

    I'm entering data across one row at a time. Not all cells in a row need to be filled for my purposes. Cells B and C will always have a value.

    I would like my userform to start writing on the next row down from a cell in B or C.

    An option could be that the userform somehow fill in all empty cells in a row with "N/A" before or when it is closed. I could add a command button for that, but what would the code be?


    excelprntscr.png



    Please Login or Register  to view this content.

+ 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. Replies: 5
    Last Post: 05-13-2014, 10:19 AM
  2. Need to find empty filled cells in a column and copy to the empty cell below
    By Grahamfeeley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-30-2014, 10:09 AM
  3. [SOLVED] Find the last cell with value in column E and Send value of textbox to the same row in col
    By MariaPap in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-24-2013, 12:15 PM
  4. [SOLVED] Macro to find the empty cell in a column and copy a adjacent row to another column.
    By naga in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-18-2013, 07:44 AM
  5. [SOLVED] Loop to find cells based on criteria, enter formula into next empty column
    By cschoyer in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-10-2012, 03:32 PM

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