Excel VBA从多个范围计算不同的值

时间:2017-09-25 12:42:25

标签: excel vba range

我想在3个不同的范围内找出不同的值(文本)。 我想我找到了一种在线方式,但它给了我一个错误。

以下是代码;

public class TreeViewModel : INotifyDataErrorInfo
{
    private readonly Dictionary<string, string> _validationErrors = new Dictionary<string, string>();

    public TreeViewModel()
    {
        Items = new List<TreeViewItem>();
        Items.Add(new TreeViewItem() { Header = "A" });
        Items.Add(new TreeViewItem() { Header = "B" });
        Items.Add(new TreeViewItem() { Header = "C" });
        Validate();
    }

    private List<TreeViewItem> mItems;
    public List<TreeViewItem> Items
    {
        get { return mItems; }
        set { mItems = value; Validate(); }
    }

    private void Validate()
    {
        if (!Items.Any(x => x.IsSelected))
            _validationErrors["Items"] = "error...";
        else
            _validationErrors.Remove("Items");
    }

    public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;

    public bool HasErrors => _validationErrors.Any();

    public IEnumerable GetErrors(string propertyName)
    {
        string value;
        if (_validationErrors.TryGetValue(propertyName, out value))
            return new List<string>(1) { value };

        return null;
    }
}

在&#34; XY_A&#34;的第二次运行中,MyData_XY给出&#34;类型不匹配&#34;错误。

我可以使用任何一种想法。

1 个答案:

答案 0 :(得分:1)

选项1:

变化:

Worksheets(Ders_Sheet_Adi).Range(OutCol & "1").Resize(MyDict.Count, 1).Value = WorksheetFunction.Transpose(MyDict.keys)

Range(OutCol & "1").Resize(1, 1).Value = WorksheetFunction.Transpose(2)

并检查它是否现在有效。如果是,则MyDict中没有任何值,因此会引发错误。

选项2: 您认为MyData_XY是什么?范围,阵列? 试着这样称呼它 - &gt; MyData_XY(1)(1,1)代替此 - &gt; MyData_XY(1,1)