+ Reply to Thread
Results 1 to 11 of 11

AutoFill Destination Unknown Range

  1. #1
    Registered User
    Join Date
    07-02-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    93

    AutoFill Destination Unknown Range

    Hopefully I can articulate this....I have a Workbook which I cannot post a lot of the code to because it is proprietary but basically I have prompted the user to load 3 files that data will be retrieved and used from. I have assigned Name Ranges to "Grids" "Elements" and "TEMP" in this code. The workbook has found, copied, and pasted data from one sheet to another. (I'll post specific code below this for clarification) In this new sheet I have moved over one cell to the right to start a new column next to it since the data is still selected from the paste. This new column was given a title and I know need to apply a formula to the first cell and copy it down the length of original data (so I have 2 equal columns).

    Please Login or Register  to view this content.
    Essentially I'm stuck on the Range since I won't know in advance how long the column is. Is there a way basically tell the code to copy the formula down until there is a blank cell and to just stop?

    Thank you!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: AutoFill Destination Unknown Range

    You can find out the last row based on a column which has data.

    For example, based on column B.

    Please Login or Register  to view this content.
    With that you can get the range for the formula.

    However, there's actually another problem - your formula isn't right.

    You wouldn't use Application.WorksheetFunction or ActiveCell in the formula, they won't be recognised on the worksheet.

    What you need is the formula as it would be written in a cell on the worksheet.

    That might look something like this.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    By the way, I know that formula is wrong, it's just for illustration.
    If posting code please use code tags, see here.

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,927

    Re: AutoFill Destination Unknown Range

    Please Login or Register  to view this content.
    Ben Van Johnson

  4. #4
    Registered User
    Join Date
    07-02-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: AutoFill Destination Unknown Range

    Yeah, I noticed the error right after I posted this question. So the formula as it would be written is how you have it shown (without the application.worksheet, etc) and if I write it that way I still get the same error. Maybe I'm not understanding?

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: AutoFill Destination Unknown Range

    Like I said I know the formula I posted isn't right.

    Do you have the formula in a cell?

    Are Grids and Elements named ranges?

    This will work, both in VBA and in a cell, but I don't know if it's the formula you want.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-02-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: AutoFill Destination Unknown Range

    The formula isn't in a cell, I'm trying to create it inside of VBA and apply it to a cell. Grids, Elements and TEMP are named ranges (via the ActiveWorkbook.Names.Add Name:=). The formula is what it needs to be as if I were going to put it just inside a cell and not use VBA.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: AutoFill Destination Unknown Range

    You don't know what the fomula is?

    Did you try the code I posted?

  8. #8
    Registered User
    Join Date
    07-02-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: AutoFill Destination Unknown Range

    Sorry, the formula is what is posted. Yes, I tried the code and it worked, but is calling C1 instead of B3 and working it's way down. In otherwords the formula needs to be applied to C3 but the Match needs to reference B3, then C4 and B4, etc... I tried changing the R1C to R3B but it apparently doesn't work that way, what is R1C exactly?

  9. #9
    Registered User
    Join Date
    07-02-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: AutoFill Destination Unknown Range

    After further investigation I now understand R1C1....if I change the R1C in the formula to R[0]C[-1] it will select the correct cell in the previous column. Thank you!

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: AutoFill Destination Unknown Range

    What do you mean 'calling' C1?

    The formula is being put in column C from row 3 down.

    I got R1C from this in the original code, but I missed the [].
    Please Login or Register  to view this content.
    Try changing R1C to R[1]C[-1], which is one row down and one column to the left from the cell the formula is in.

    PS You could just use B4 in the formula and change FormulaR1C1 to Formula.

  11. #11
    Registered User
    Join Date
    07-02-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: AutoFill Destination Unknown Range

    Good to know, thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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