簡體   English   中英

如何比較同一工作簿但不同工作表中的兩個命名范圍?

[英]How to compare two named ranges in same workbook but different worksheets?

我試圖將一個命名范圍中的值與另一個工作表上另一個表中的另一個命名范圍進行比較。

名稱范圍:工作簿范圍

Current Roster = WSheet1
New Roster = WSheet2
CurrentNameList = Column F of CurrentRoster
NewNameList = Column F of New Roster

問題: Time out - Type Mismatch

If c.Value = Range("NewNameList").Value Then

這是我開始的地方:

Sub Compare()
    For Each c In Range("CurrentNameList")
        If c.Value = Range("NewNameList").Value Then
           ThisWorkbook.Worksheets("CurrentRoster").Range("CurrentNameList").Offset(, 26).Value = "Active"
        Else
            ThisWorkbook.Worksheets("Current Roster").Range("CurrentNameList").Offset(, 26).Value = "InActive"
        End If
    Next
End Sub

先感謝您。

如果你的名字是工作簿范圍的,你可以參考這樣的范圍:

    Dim wb As Workbook, c As Range, m

    Set wb = ThisWorkbook 'always scope your ranges as explicitly as you can
    
    For Each c In wb.Names("CurrentNameList").RefersToRange.Cells
        'Use Match to check if a value in is a list
        m = Application.Match(c.Value, wb.Names("NewNameList").RefersToRange, 0) 'is the value in the list?
        'Did we get a match? If not then m is an error value
        c.Offset(0, 26).Value = IIf(IsError(m), "InActive", "Active")
    Next c

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM