对象_worksheet的运行时错误1004方法范围失败

时间:2020-05-10 18:11:12

标签: excel vba

当D列中的数据更改时,我尝试应用VLOOKUP函数。我在工作簿模块中应用了完全相同的代码,并且工作得很好。但是,当我将其应用于特定的工作表对象(设置为在单元格发生更改时运行)时,出现上述错误。谢谢您的帮助!

using System.Collections.Generic;

public sealed class DayTime
{
    public static readonly DayTime Morning = new DayTime("Morning", InnerEnum.Morning);
    public static readonly DayTime Afternoon = new DayTime("Afternoon", InnerEnum.Afternoon);
    public static readonly DayTime Night = new DayTime("Night", InnerEnum.Night);

    private static readonly List<DayTime> valueList = new List<DayTime>();

    static DayTime()
    {
        valueList.Add(Morning);
        valueList.Add(Afternoon);
        valueList.Add(Night);
    }

    //the inner enum needs to be public for use in 'switch' blocks:
    public enum InnerEnum
    {
        Morning,
        Afternoon,
        Night
    }

    public readonly InnerEnum innerEnumValue;
    private readonly string nameValue;
    private readonly int ordinalValue;
    private static int nextOrdinal = 0;

    private string description;

    internal DayTime(string name, InnerEnum innerEnum)
    {
        this.description = name;

        nameValue = name;
        ordinalValue = nextOrdinal++;
        innerEnumValue = innerEnum;
    }

    public string Description
    {
        get
        {
            return description;
        }
    }

    //the following methods reproduce Java built-in enum functionality:

    public static DayTime[] values()
    {
        return valueList.ToArray();
    }

    public int ordinal()
    {
        return ordinalValue;
    }

    public override string ToString()
    {
        return nameValue;
    }

    public static DayTime valueOf(string name)
    {
        foreach (DayTime enumInstance in DayTime.valueList)
        {
            if (enumInstance.nameValue == name)
            {
                return enumInstance;
            }
        }
        throw new System.ArgumentException(name);
    }
}

0 个答案:

没有答案