+ Reply to Thread
Results 1 to 10 of 10

variable fill range

Hybrid View

  1. #1
    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.

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

    Correction to code

    Sorry about that...try this instead. I highlighted the corrections for clarity:
    Private Sub Worksheet_Activate()
    Dim name1, name2, varRange, c
    
    ' Assign named formulas to variables...
    name1 = ActiveWorkbook.Names("BinTest")
    name2 = ActiveWorkbook.Names("Range")
    ' Get value of named 'Range' workbook object- strip off the '=' sign...
    RowCount = ActiveSheet.Range(name2).Value
    ' Ensure Excel worksheet row limit isn't exceeded...
    If RowCount > 65500 Then
         MsgBox "Your value for 'Range' exceeds the row limit for EXCEL worksheets."
         Exit Sub
    End If
    ' Define the range of cells to insert the named "BinTest" formula
    ' Start at cell A37 & add the value of name "Range" to the row to include in range of cells...
    varRange = ActiveSheet.Cells(37, 1).Address & ":" & Cells((37 + Range(name2).Value), 1).Address
    
    ' Insert the "BinTest" formula in each cell of the range...
    For Each c In Range(varRange)
        c.Formula = name1
    Next
    End Sub
    theDude

  3. #3
    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.

  4. #4
    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

  5. #5
    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

  6. #6
    Forum Contributor
    Join Date
    11-16-2004
    Posts
    282
    Replace this line of code:
    rowCount = ActiveSheet.Range(name2).Value
    with this line of code:
    rowCount = ActiveWorkbook.Worksheets("BinSize").Range(name2).Value
    Replace this line of code:
    varRange = ActiveSheet.Cells(37, 1).Address & ":" & Cells((37 + Range(name2).Value), 1).Address
    with this line of code:
    varRange = ActiveSheet.Cells(37, 1).Address & ":" & Cells((37 + RowCount), 1).Address
    Hope this helps,
    theDude

  7. #7
    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