You can pass a range to a UDF as a named range, or directly:
=BS(A1:G26, 3)
You can pass a range to a UDF as a named range, or directly:
=BS(A1:G26, 3)
Entia non sunt multiplicanda sine necessitate
Hello dewittig,
Your macro works correctly as UDF when rewritten as shown here. It also will work correctly in VBA. When specifying a range in VBA you will need use the word Range, e.g. Range("C1:G25"). If you are referencing a range that is on a worksheet other than the ActiveSheet, you will need to prefix the range with the worksheet name.
![]()
Function BS(rng As Range, iRow As Integer) Dim c As Range Dim countt As Long 'Test operations With rng.Rows(iRow) For Each c In .Cells Addx = c.Address If c.Interior.ColorIndex = 37 Then countt = countt + 1 Next End With BS = countt End Function
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Thank You both for your help. Your code works correctly, however I am still having problems calling the code from within a cell, but it works when called through a button.
Here's the code within the button:
Range("w16") = BS(Range("A1:G26"), 3)
Here's the code within the cell:
=BS(A1:G26,3)
I have also tried:
=BS(Range("A1:G26"),3)
=BS(Range(A1:G26),3)
The button returns "2" (which is correct)
The cell says "#REF!"
Any ideas?
Hello dewittig,
The macro I wrote works fine in both instances. Your syntax is correct for the button and the first syntax for cell is also correct. Did you place the macro in a Standard VBA module? If not, the macro will not be visible to the worksheet.
Thank You Leith!
After a good nights sleep all is working great!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks