Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

custom functions

ResolvedVersion 2007

Diane has attended:
Excel VBA Advanced course

Custom functions

Hi
I've created a quick custom function where I want the background colour of a cell to change if another cell has the word 'yes' entered.
Is there anything obviously wrong with the below?

Function ThreeD(B As String)

If B = "Yes" Then

ThreeD.Interior.Color = RGB(127, 127, 127)

Else

ThreeD = 0

End If

End Function

Thanks! Diane

RE: custom functions

Hi Diane

Thanks for the question

It is not possible to use a function to achieve what you are attempting

I have created the following sub procedurenwhich you can adapt to solve your problem

Sub ThreeD()

Dim B As String
B = Cells(1, 1).Value

If B = "Yes" Then

Cells(1, 1).Interior.Color = RGB(127, 127, 127)
Else
Cells(1, 1).Interior.Color = RGB(0, 0, 0)

End If

End Sub


Hope this helps

Regards

Stephen

Tue 23 Feb 2010: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Freeze Rows and Columns to keep lables displayed

You can freeze rows and columns in your worksheet so they don't move.

This allows you to keep row and column labels displayed on your screen as you move through a large worksheet.

Click below and/or to the right of the cell(s) you want to freeze. (NB. Excel freezes ALL the rows above and ALL the columns to left of the selected cell)

Click on the 'Windows' menu and selct 'Freeze Panes'.

Lines appear in your worksheet. The required rows and columns are frozen and remain on your screen as you move through your worksheet.

To unfreeze rows and columns, click on 'Window' menu and select 'Unfreeze Panes'.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.