Reza
Reza

Reputation: 3

excel 2013 interior.color "#Value!" error

When i try to change color of a cell using a function like this:

Function abcd()
    Worksheets("Sheet1").Cells(1, 1).Interior.ColorIndex = 3
End Function

by calling the function from a cell "=abcd()" it returns a "#Value!" error.

but if i use a sub and run it manually (by pressing the run button) it will work fine.

Sub abcd()
    Worksheets("Sheet1").Cells(1, 1).Interior.ColorIndex = 3
End Sub

but i want call the function from a cell and i dont want to use conditional formatting. what am i doing wrong?

Upvotes: 0

Views: 185

Answers (1)

Gary's Student
Gary's Student

Reputation: 96753

A function can only return a value to a cell, it cannot change formats. Use Conditional Formatting

Upvotes: 1

Related Questions