+ Reply to Thread
Results 1 to 8 of 8

Dragging formula to undefined length

  1. #1
    Registered User
    Join Date
    03-26-2010
    Location
    Charleston, SC
    MS-Off Ver
    Excel 2010
    Posts
    42

    Dragging formula to undefined length

    Hi all,

    I'm creating a macro to apply to a report that will change every day. One of the columns contains a formula that I'm including in the macro. I have been placing the formula in the first cell (B2), and then dragging it down to encompass all of the data in the example worksheet that I'm using, but that will change every day. Is there a way around this?

    Right now I'm selecting a range that goes well over what the report should ever generate (B2:B500), but is there a way to define this by saying "B2:Whenever the data stops"?

    Thanks!
    David
    Last edited by dhd2005; 04-07-2010 at 12:23 PM. Reason: Issue Solved

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Dragging formula to undefined length

    Post the code that you have or an example workbook
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    03-26-2010
    Location
    Charleston, SC
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Dragging formula to undefined length

    Hi royUK,

    I just attached a very simple example worksheet. Columns B and C contain LOOKUP formulas. When this report is run, Column A (automatically generated information) may have 3 items, or 5 items, or in the case of my actual spreadsheet, 150 items. What I want to do is fill in the formula in Columns B & C down to where the data ends.

    So if Column A only goes to A3, automatically drag the formula in Column B to B3. If it goes to A13, B needs to go to B13. And so on.

    Any suggestions?

    Thanks,
    David
    Attached Files Attached Files

  4. #4
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Dragging formula to undefined length

    If there are no blank cells in column-A you can use this to fill down columns-B & C for as many rows as contain entries in column-A

    Please Login or Register  to view this content.


    If there are blank cells in column-A, use this code.
    Please Login or Register  to view this content.
    Last edited by Palmetto; 04-01-2010 at 02:55 PM. Reason: Added additional code
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  5. #5
    Registered User
    Join Date
    03-26-2010
    Location
    Charleston, SC
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Dragging formula to undefined length

    Hi all,

    I apologize, looking back at my example, it was profoundly unclear what I was attempting to communicate. I've uploaded a slightly different example of what I'm trying to accomplish:

    Column A will populate with information of varying length. I'm inserting the function into B2, and dragging it down as far as column A has data - whether that is 13 rows or 130 rows.

    My current code looks something like this:

    Range("B2").Select
    Selection.AutoFill Destination:=Range("B2:B14"), Type:=xlFillDefault
    Range("B2:B14").Select
    Range("A1").Select

    Can you advise if the above is still applicable, and if so, how to apply it to my current code?

    Thanks again for all of your help!

    -David
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    03-26-2010
    Location
    Charleston, SC
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Dragging formula to undefined length

    Sorry to be a pest, but can anyone provide any guidance based on my last post? I'm getting some pressure to have this completed today; any additional help would be greatly appreciated! Thanks again!

  7. #7
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Dragging formula to undefined length

    Delete the existing code in the module and use this code which is slightly modified to work with your sample workbook.


    Please Login or Register  to view this content.
    BTW: per the Forum rules all VBA code must be wrapped in code tags. Please edit your last post and add the code tags. Click the link to view how to go about it.

  8. #8
    Registered User
    Join Date
    03-26-2010
    Location
    Charleston, SC
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Dragging formula to undefined length

    That is exactly what I needed! Thank you so much!

    And I'll be sure to wrap VBA code in code tags going forward; thank you for the heads up!

    -David

+ 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