+ Reply to Thread
Results 1 to 10 of 10

Code to place userform data into next empty row

  1. #1
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    316

    Code to place userform data into next empty row

    Hi,

    I have the below code which currently populates the next empty row with information from my userform. However this code only works if Column A is empty, unfortunately I will always have data in column A is there a way to change the code so it looks for the next empty row in Column B?

    This is an (Extract of my code)

    Please Login or Register  to view this content.
    Many thanks
    Michelle

  2. #2
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Re: Code to place userform data into next empty row

    Hi Michelle,

    Why don't you take a look at this - it's a very simple change...

    Tony
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    316

    Re: Code to place userform data into next empty row

    Hi Tony

    Thanks for replying, as you can tell i am not overly knowledgeable on VBA and seem to somehow muddle my way through. However I am not sure how to apply the code you gave me to my userform? This is what i have done.

    Please Login or Register  to view this content.
    Can yuo help me understand how i intergrate it please, thanks for helping.

    Michelle

  4. #4
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    316

    Re: Code to place userform data into next empty row

    Hi Tony

    I thought i had sussed it but i
    Last edited by michelle 1; 12-10-2013 at 10:06 AM.

  5. #5
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    316

    Re: Code to place userform data into next empty row

    Hi Tony

    I thought i had sussed it but i notice its inserting the information on the last Cell in column 2 containing information instead of the next row down which is the empty cell.

    Please Login or Register  to view this content.
    Last edited by michelle 1; 12-10-2013 at 10:06 AM.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Code to place userform data into next empty row

    If you want to populate column B, change this line

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Re: Code to place userform data into next empty row

    Ah!

    You'll need to add "+ 1" to the expression in FindEmptyCell.

    The expression as it is now actually finds the last used cell. You need to point one past that to get an empty cell.

    HTH

    Tony

  8. #8
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    316

    Re: Code to place userform data into next empty row

    Thanks Tony, where abouts do i show the "+1" in my code?

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Office 365
    Posts
    286

    Re: Code to place userform data into next empty row

    Well, let's think for a minute.

    Your function is going to tell you the number of a row. (FindEmptyCellInColumn gives you the row number of an empty cell)

    It does this by figuring out the row number (.Row) of the range that comprises the last used cell (Sheet2.Cells(Sheet2.Rows.Count, pColumn).End(xlUp))

    So the expression
    Please Login or Register  to view this content.
    gives you the row number of the last used cell (ooops - that was my earlier mistake, wasn't it
    So, in order to get the row past that, we simnply add 1 to that value. You could do it by having a temporary variable to get the last used row, and then adding one to that, or you could economize by simply adding 1 right onto the end of the expressions:
    Please Login or Register  to view this content.
    At the risk of sounding a little bit stuffy (hey, I'm an Old Fart, I'm allowed to ), your questions indicate that you are flying a little by the seat of your pants when it comes to this coding stuff. May I recommend that you read the erly chapters of wonderful book called Algorithms + Data Structures = Programs

    This is by Niklaus Wirth, one of the pioneers of structured programming, and its more important design concept, Stepwise Refinement. Te later chapters are pretty heavy going, but the first section on Fundamental Data Structures is still (after some 40 years in the field) regular bed-time reading - it's that good!

    HTH

    Tony

  10. #10
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    316

    Re: Code to place userform data into next empty row

    Thanks Tony, Yes i am learning as i go along with the help of VBA for dummies. Appreciate your help with this one.

+ 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: 0
    Last Post: 10-04-2012, 08:21 PM
  2. [SOLVED] Place data from VBA Userform TextBox into a new row on a worksheet every time
    By Sugarray in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-09-2012, 08:51 AM
  3. Place data from sheet1 into first empty row on Sheet2
    By mikey6strings in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-29-2011, 03:10 PM
  4. Help with code to have database userform add values to next empty row.
    By dcgrove in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-03-2010, 05:17 PM
  5. [SOLVED] Userform finding next row to place data
    By BrianW in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2006, 05:45 PM

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