+ Reply to Thread
Results 1 to 10 of 10

variable fill range

  1. #1
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163

    variable fill range

    Using VBA I need to paste a named formula “BinTest” into a range of cells in a column. Starting at A37. The length of the range of cells is dependant upon the value of another name “Range”. I want this to fire when the worksheet is selected if that is possible.

    I think I need to use a fill function and somehow check the value of “Range” and then say fill down from A37 but I have no idea where to start.

    Any help, code examples, etc. will be appreciated

    Robert

  2. #2
    Forum Contributor
    Join Date
    11-16-2004
    Posts
    282

    Inserting named formulas in cells using VB

    My solution will run when you select the worksheet if you copy this code to the worksheet object you want to run it against. It assumes that your name 'Range' is just an integer value that equals the number of rows you want to insert the named 'BinTest' formula starting at cell A37:
    Please Login or Register  to view this content.
    Hope this helps,
    theDude
    Last edited by theDude; 10-07-2006 at 07:52 AM. Reason: My error in varRange definition - didn't account for large row count (increased allowable value to 5-digit range that equals max Excel row limit of 65,536 rows).

  3. #3
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163
    thanks Dude, ill be trying that out somethme this weekend

  4. #4
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163
    Dude, I get a runtime error 13, "Type mismatch", at the line:
    rowCount = Int(Mid(name2, 2, 5))

    I think is because "Range" is actualy a named range (cell) with a simple formula in it that calculates the "range" value.
    So far, I haven been able to resolve it.
    Last edited by Hammer_757; 10-08-2006 at 10:26 PM.

  5. #5
    Forum Contributor
    Join Date
    11-16-2004
    Posts
    282

    Correction to code

    Sorry about that...try this instead. I highlighted the corrections for clarity:
    Please Login or Register  to view this content.
    theDude

  6. #6
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163
    thanks Dude, but now I get a" Runtime error 1004, Application-defined or object-defined error. at:

    rowCount = ActiveSheet.Range(name2).Value

    I noticed in the Locals Window that name2 value is "="BinSize!$B$26""
    the equal sign and double quotes dont look right?

    I tried to mimic your first code with
    rowCount = ActiveSheet.Range(Mid(name2, 2, 5)).Value
    to strip the equals sign off, but I still get the problem
    Last edited by Hammer_757; 10-09-2006 at 02:04 PM.

  7. #7
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163
    Actualy that was a problem with the named range, not the code, now that its fixed rowCount loads just fine, with the correct value.

    Robert

  8. #8
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163
    I still have the problem (Application-defined or object-defined error. at:
    rowCount = ActiveSheet.Range(name2).Value)
    However, “Range” comes from a different worksheet, “BinSize”. (“Range” IS a global named range)
    If worksheet "BinSize" is selected in excel and the code is ran, it works fine. If the correct worksheet, Htestc, is selected the error occurs.

    I tried changing the line to:
    rowCount = ActiveWorkbook.Range(name2).Value
    and get: “Object doesn't support this property or method (Error 438)”
    Im getting beat up by somethin that seems pretty simple

  9. #9
    Forum Contributor
    Join Date
    11-16-2004
    Posts
    282
    Replace this line of code:
    Please Login or Register  to view this content.
    with this line of code:
    Please Login or Register  to view this content.
    Replace this line of code:
    Please Login or Register  to view this content.
    with this line of code:
    Please Login or Register  to view this content.
    Hope this helps,
    theDude

  10. #10
    Forum Contributor
    Join Date
    03-21-2004
    Location
    Norwich, CT USA
    MS-Off Ver
    Excel 2010
    Posts
    163
    yes, it works.
    Thanks for the help and education!

+ 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