+ Reply to Thread
Results 1 to 19 of 19

Macro to autofill formulas to the last row with data

  1. #1
    Registered User
    Join Date
    08-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    87

    Macro to autofill formulas to the last row with data

    Hi all,

    I have a question. I am currently working on a excel project. The excel doc has 2 columns (last name (column A) and first name (column B)). every month i would create a CONCATENATE formula in column C to combine first name and last name to make up full name..

    Then I would autofill the formula down to the last row of data.. i would like to automate this process with macro so I've been playing around with it for some time but the code does not seem to be working properly.

    The issue im having is with regards to the autofill. I need a macro that would automatically fill the concatenate formulas down to the LAST ROW OF DATA! the code im having now is until row 9219. but the number of rows vary by month.. thus i want to have a macro that would automatically fill until last row of data..

    Thanks for the help!

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Macro to autofill formulas to the last row with data

    Try

    Please Login or Register  to view this content.
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    08-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Macro to autofill formulas to the last row with data

    Hi Jeff!

    I think it's working fine now. One other issue though is that the font changes drastically. The font on the 'full name' column seems to be different from the last name and first name columns. the size is different too... is there any way to keep all font and font size the same?

    thanks!

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Macro to autofill formulas to the last row with data

    You could set it within the code to what you want...

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Macro to autofill formulas to the last row with data

    Hi Jeff!

    thanks for the prompt reply. Another question, is there any macro code that i can use to export that excel sheet to access?

    Thanks!

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Macro to autofill formulas to the last row with data

    How often are you going to be doing this? Is it once a day, once a week, once a month, or more?

  7. #7
    Registered User
    Join Date
    08-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Macro to autofill formulas to the last row with data

    once a month possibly. could be up to 2-3x a month

  8. #8
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Macro to autofill formulas to the last row with data

    I don't mess with Access all that much, but two options that I know of.

    While in Excel, highlight the range you want to import into Access with the header row >> Copy

    With Access open >> right click on the All Access Objects pane on the left side of the screen and paste. Follow the on-screen instructions and all done.

    The 2nd, with Access open >> create >> Macro >> TransferSpreadsheet

    Not entirely sure the action arguments, but if you read the tips or do a quick google search you can probably knock it out rather easily.

    Again, since I'm not up on this method I would have to do a google search myself to ensure I get it right.

    I use the first method quite a bit and works great for my purposes.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  9. #9
    Registered User
    Join Date
    08-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Macro to autofill formulas to the last row with data

    Hi jeff,

    Just wanted to follow up on this thread. I've been using your code to autofill till the last row of data. however, there's a minor issue when i imported the sheet to access.

    so i currently only have 9200 rows of data in excel right, however when i import the excel to access, access adds an extra of 8 empty rows to the new table. so, in the end i end up with 9208 rows (records).

    do you have any idea why this might happen?

    thanks!
    Last edited by jeffreybrown; 09-10-2012 at 06:44 PM. Reason: Removed unnecessary quote. Please do not post entire quotes.

  10. #10
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Macro to autofill formulas to the last row with data

    My first thought is to check the rows from the Excel sheet to determine the real end.

    Press Ctrl + End in the Excel sheet and see where the end falls.

  11. #11
    Registered User
    Join Date
    08-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Macro to autofill formulas to the last row with data

    Hi Jeff,

    I think you're right.

    When I pressed Ctrl + End, it points me to the correct end (where the last data is, say it's row 50) in the excel workbook that I used when creating this code. However when I tried it with the other ones, it didn't point me to where the last data is. It stopped at row 50 regardless whether there's any data there or not. Why is that? Is there any way I can correct this?

    Because of this, whenever I imported the sheet to access, access keeps on generating 50 rows or records regardless whether there are only 20 rows of data, etc.

    Here's the full code that I have now. I have expanded your code (as you can see) Thanks!

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 09-12-2012 at 07:55 AM.

  12. #12
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Macro to autofill formulas to the last row with data

    I've always had good luck running this to reset the last cell. Select the last cell in your workbook and then run

    Sub makelastcell() from here

  13. #13
    Registered User
    Join Date
    08-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Macro to autofill formulas to the last row with data

    Hi Jeff,

    I am not sure I understand what the coding really means... I am fairly new on coding.... Does this mean I have to insert a new module?

    Thanks
    Last edited by jeffreybrown; 09-12-2012 at 07:54 AM. Reason: Removed quote

  14. #14
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Macro to autofill formulas to the last row with data

    Yes, you can insert this code in a new module...

    Highlight macro to copy >> Ctrl + C >> Open your workbook
    Alt + F11 >> opens the Visual Basic Editor (VBE)
    Ctrl + R >>opens the Project Explorer (if not already open on left side of screen)
    Insert menu >> Module or Alt + I, M >> activates the Insert menu and inserts a Standard Module
    Paste code >> Ctrl + V (right side of screen)
    Alt + Q >> exits VBE and returns to Excel
    Back in Excel >> place your cursor on the last cell >> Alt + F8 >> Macro Dialog Box >> Highlight macro >> Run

    Note: If range of data is A1:G500 >> place cursor on G500

  15. #15
    Registered User
    Join Date
    08-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Macro to autofill formulas to the last row with data

    Hi Jeff,

    so does that mean I will have to build this macro everytime the range of data is different? The spreadsheets that I'm gonna be using the macro on have different data ranges though... they all have different data end... (e.g. spreadhsheet 1 might end on row 50, spreadsheet 2 might end on row 20, spreadsheet 3 might end on row 60 and so forth)..

    I found this code in another thread. Do you think this code below will work or is it just the same as your code? Thanks!

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 09-12-2012 at 12:12 PM.

  16. #16
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Macro to autofill formulas to the last row with data

    The Macro will find the end by using the variable LR as in post #4 and yes the code you posted in #15 is essentially the same.

    Also, very rarely is it ever necessary to use select in your code.

    http://www.tushar-mehta.com/excel/vb...rder/index.htm

  17. #17
    Registered User
    Join Date
    08-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Macro to autofill formulas to the last row with data

    Hi Jeff,

    I think I managed to find a way around it. After I imported it to access, I used delete query to delete all the blank records using null values function. It seems to be working properly now.

  18. #18
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Macro to autofill formulas to the last row with data

    Sounds good...glad you found a workable solution and thanks for the feedback

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  19. #19
    Registered User
    Join Date
    08-31-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Macro to autofill formulas to the last row with data

    was wondering if you know any forum for access where there's lots of traffic... there seems to be one here but i'm not sure whether there's a lot of people going there or not since it is an excelforum. thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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