0

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?

Reza
  • 3
  • 3
  • Your function 'abcd()' does not return anything. If you want to return something, add " abcd = return_value " befor 'End Function'. Assing a valut to name of function is the way to specify return value in VBA. – Fumu 7 Sep 07 '14 at 12:16

1 Answers1

1

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

Gary's Student
  • 95,722
  • 10
  • 59
  • 99