Advertisement

07.19.2008 at 02:02PM PDT, ID: 23579440
[x]
Attachment Details

Writing a formula using VBA

Asked by piyushdabomb in Microsoft Excel Spreadsheet Software

Tags: Microsoft, Office, 2002

This is going to sound newbish, but I need help figuring out what I'm doing wrong here.

I want to write  a function that essentially takes a range and if the average in the range is > 8, color every cell in the range using interiorindex. I attempt to write it but I keep getting a #VALUE error.

Check it out:

Public Function avgdays(Rng As Range)

avgdays = "=AVERAGE(" & Rng & ")"

If ActiveCell.Value > 8 Then
    For Each cell In Rng
        cell.Interior.ColorIndex = 6
    Next
End If
End Function

I had 6 values from Range("A1") to Range("F1") and whenever I type in =avgdays("A1:F1"), I get #VALUE ....

I've never written functions before. What am I doing wrong here?Start Free Trial
[+][-]07.19.2008 at 02:27PM PDT, ID: 22043719

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 02:30PM PDT, ID: 22043731

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 02:47PM PDT, ID: 22043770

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Excel Spreadsheet Software
Tags: Microsoft, Office, 2002
Sign Up Now!
Solution Provided By: jpaulino
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.19.2008 at 03:35PM PDT, ID: 22043837

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 03:38PM PDT, ID: 22043843

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 05:58PM PDT, ID: 22044114

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.19.2008 at 06:13PM PDT, ID: 22044148

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628