简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM