+ Reply to Thread
Results 1 to 8 of 8

Transferring data to the first blank row in different sheet using VBA

  1. #1
    Registered User
    Join Date
    07-25-2017
    Location
    England
    MS-Off Ver
    2013
    Posts
    86

    Transferring data to the first blank row in different sheet using VBA

    Hi,
    I am using excel to create, essentially a transaction system/ database. Every time I buy or sell using the entry page, i press the macro button which i want to send the data I have inputted on the entry page to a database. However, I will be using this allot over the space of a year, so i have attempted to send all the data in the next blank row after each press of the button. So far, it is sending all the correct data over when the correct option box is pressed (either buy or sell on the entry page) however, it is not always putting it in the correct row. It seems to overwrite the row that it previously used sometimes. My code is as follows:

    Please Login or Register  to view this content.
    I imagine that the problem lies within the RowNumber declaration, but I do not understand why, if someone could help clear this issue up, that'd be great. Thanks

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

    Re: Transferring data to the first blank row in different sheet using VBA

    Is there any instance where column A on the Database sheet would be empty when you submit a record?
    If so this is what is causing the overwriting.

    There are other ways of defining the last row but which would be best for you would very much depend on data layout, and without a sample workbook to look at it's difficult to make further suggestion.

    BSB

  3. #3
    Registered User
    Join Date
    07-25-2017
    Location
    England
    MS-Off Ver
    2013
    Posts
    86
    Quote Originally Posted by BadlySpelledBuoy View Post
    Is there any instance where column A on the Database sheet would be empty when you submit a record?
    If so this is what is causing the overwriting.

    There are other ways of defining the last row but which would be best for you would very much depend on data layout, and without a sample workbook to look at it's difficult to make further suggestion.

    BSB
    Yes, there is an instance where col A will be empty. I want it to search for the first row that has absolutely nothing in it. There are columns that should never be empty if the entry form has been used. But just in case someone inputs incorrectly i would rather it look for the first row that is completely empty, i.e. none of the columns A-Z for that row have any entrys. Is there a way to code this for a range of columns?

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

    Re: Transferring data to the first blank row in different sheet using VBA

    Certainly is. Assuming your data, along with any headers, starts on Row 1 then you can use:
    Please Login or Register  to view this content.
    UsedRange will look at all data down to the last row with anything in it. Then by using Rows.Count you simply count the number of rows in that range. The +1 just adds one on to make the row you'll stamp data to the first blank one.

    BSB
    Last edited by BadlySpelledBuoy; 07-19-2018 at 06:36 AM.

  5. #5
    Registered User
    Join Date
    07-25-2017
    Location
    England
    MS-Off Ver
    2013
    Posts
    86

    Re: Transferring data to the first blank row in different sheet using VBA

    Thanks, I have used this and it worked. However, upon deleting the test data in my 'database' the usedrange is picking up the wrong range. I have read online that is rather unreliable and if you delete data it will not work effectively, I am guessing that is what has happened. I was just wondering if you knew any other way I could get the same result, or perhaps a way to reset the usedrange. Thanks

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

    Re: Transferring data to the first blank row in different sheet using VBA

    This used to happen to me back when I was using Excel 2007 but since using 2010 and 2016 it doesn't happen anymore. If I delete data the UsedRange corrects itself.

    Without a long winded method of testing each column for a last row and then using the greatest of those for your RowNumber variable, the easiest solution would be to use a column that will ALWAYS be populated via the form. If there isn't one of those, make one. Something like the ID field in an Access table.

    BSB

  7. #7
    Registered User
    Join Date
    07-25-2017
    Location
    England
    MS-Off Ver
    2013
    Posts
    86

    Re: Transferring data to the first blank row in different sheet using VBA

    ok, the ID field sounds like a good idea. Thanks for your help

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

    Re: Transferring data to the first blank row in different sheet using VBA

    No problem. Happy to help

    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] transferring data from one sheet to another - finding the next blank column while matching
    By jousley in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-27-2016, 01:48 PM
  2. Replies: 1
    Last Post: 07-25-2013, 05:09 PM
  3. [SOLVED] Discard blank cells while transferring data
    By jackee96 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-19-2013, 03:32 PM
  4. Not transferring data if it is blank
    By NewbieRachel in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-31-2013, 02:29 PM
  5. [SOLVED] VBA. transferring data from one sheet to another, where cells in Col A are not blank
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-04-2012, 08:21 PM
  6. Transferring multiple data from the same sheet in a single cell In another sheet.
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2012, 09:33 AM
  7. Replies: 0
    Last Post: 05-29-2009, 09:42 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