+ Reply to Thread
Results 1 to 8 of 8

Fill Macro

  1. #1
    Registered User
    Join Date
    06-16-2005
    Posts
    5

    Fill Macro

    Hi

    I am new to macros, and havent any past experience with programming. I am looking for a way of making a macro that looks for the last row in a table of three columns, and fills it down a row.

    A rough idea of what i want can be found here Macro Question

    Thanks in advance, ben

  2. #2
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    Give this a try

    Please Login or Register  to view this content.
    I'm not sure what you mean by "It would be good if it could auto put in another value from another reference"
    Do you want one of the cells Ax, Bx or Cx to have a fixed value?
    or depending on what row you are filling into it will pull a value from somewhere else on the same worksheet or another worksheet in the same workbook, etc.
    What value do you want it to put in?

  3. #3
    Registered User
    Join Date
    06-16-2005
    Posts
    5

    Question

    To insert a value into the b and c columns from another cell reference, it would be good if this can be achieved, but it isnt necessary

    I have updated the situation slightly, and here is another demonstration: Macro Help

    The last that you sent me appears to be adding rows, but I'm not sure what it is filling; the rows are blank :S
    Last edited by benb7760; 06-16-2005 at 03:01 PM.

  4. #4
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    The macro I sent you will find the last used row on your sheet and then fill down one row from there in columns A, B, and C.
    Since your column A has the Month-Year then it will increment that value.
    It appears that your column B and C have numeric values so it will simply copy that same value into the next row.

    Do you want the value that is currently in the Overview section of your spreadsheet to be filled into column B and C?

    If that is the case try this.

    Please Login or Register  to view this content.
    I have modified the positions to reflect the positions of your two tables in the MacroHelp example you show.

    HTH

  5. #5
    Registered User
    Join Date
    06-16-2005
    Posts
    5
    That works exactly how i want it, there is one slight problem, that it starts filling from row 50, when the current row it should start from is 16, and because its starting all the way down there, it is not filling the date because it isnt in the cell above it. Any way to get it to start filling from row 16, where it needs to ?

    If you dont understand: Screenshot and annotation

    Thanks for all the help so far!

  6. #6
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    benb7760,
    That is one drawback with the using the UsedRange command the way I have in this macro.
    If you have ever done something in a row below the bottom of your table (lower than row 15 in this case) it will find that with UsedRange.Rows.Count.

    A quick and easy work around is to highlight all rows (or at least several hundred) starting at the bottom of your table (row 16) then right clicking and select 'delete' (Don't just use the delete keyboard button).

    This will clear any reminants of activitiy on the lower rows of your sheet then the macro will run correctly.

    I have seen posts which suggest a more robust way to find the last populated row in the sheet and will check if I can find that information.

  7. #7
    Registered User
    Join Date
    06-16-2005
    Posts
    5
    thank you, everything is working fine. If you do find a better way to find the last row, it'd be great if you could show me how to work it into the formula. The only problem left now is that the cells that you showed me how to do automatically:
    Range("C" & NumRows + 1) = Range("F6")
    Range("D" & NumRows + 1) = Range("F7")
    Arent getting the cell formatting that i desire. Is there a way to do this?

    Thanks for all your help!

  8. #8
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    If you are always going to be working on the same sheet then the easiest way to do it would be to preformat the cells with the desired format.

    You can also do it programically by adding the following lines

    Range("C" & NumRows + 1) = Range("F6")
    Range("C" & NumRows + 1).number.format = "$#0.00"
    Range("D" & NumRows + 1) = Range("F7")
    Range("D" & NumRows + 1).number.format = "$#0.00"

    If you want a different number format then I'd suggest recording a macro and manually changing the numberformat of a number of different cells and that will give you an idea of how the syntax will look for various types of numberformats.

    To count the number of rows in a specific column you can replace the NumRows line with the following:

    NumRows = Cells(Rows.Count, "B").End(xlUp).Row

    This assumes your Dates are in Column B as in your example.

    HTH

+ 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