Results 1 to 1 of 1

Use a function in another workbook

Threaded View

  1. #1
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Use a function in another workbook

    Hi,

    I wanted a way to count the number of cells that are red, after some research I found a function that worked. however the function is located in the workbook that I run my script from so the new workbook that is created via my script does not have the fuction in it.

    How can I place the formula into the cell in the second workbook that uses the function in the main workbook?

    Here is the color counting script that I am using. and the formula that I want in the cell looks something like this below. I suppose once I got the number of cells that are red I would then need to replace the formula with the value because once my main workbook closed the formula would not work anymore. Unless I could place the function in the new workbook?

    Any Idea's?

    Thank You, Mike

    Range("B11").FormulaR1C1 = "=CountColor(R[10]C[10],R[11]C[10]:R[" & lrow & "]C[10])"
    Function CountColor(rColor As Range, rSumRange As Range)
    
    
    'Counts cells based on a specified fill color.=countcolor(B2,B1:B10)
    
    
    Dim rCell As Range
    
    Dim iCol As Integer
    
    Dim vResult
    
    
    
    iCol = rColor.Interior.ColorIndex
    
    
    
       For Each rCell In rSumRange
    
        If rCell.Interior.ColorIndex = iCol Then
    
             vResult = vResult + 1
    
        End If
    
       Next rCell
    
    
    
    CountColor = vResult
    
    End Function
    Last edited by realniceguy5000; 04-01-2011 at 08:55 AM.

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