gpt4 book ai didi

excel - 从表 1 和表 2 匹配或查找值

转载 作者:行者123 更新时间:2023-12-04 20:01:35 25 4
gpt4 key购买 nike

我有这段代码可以检查 h22 中的值是否与 i 列中的条目匹配。如何更改它应该检查 h22 是否与 i 列上的最后一个值完全匹配的代码?

Option Explicit

Sub Macro()

Dim oWs As Worksheet
Dim rSearchRng As Range
Dim lEndNum As Long
Dim vFindVar As Variant

Set oWs = ActiveWorkbook.Worksheets("Sheet2")
lEndNum = oWs.Range("I1").End(xlDown).Row
Set rSearchRng = oWs.Range("I1:I" & CStr(lEndNum))
Set vFindVar = rSearchRng.Find(Range("H22").Value)

If Not vFindVar Is Nothing Then
MsgBox "Match"
Else
MsgBox "No Match Found"
End If

End Sub

最佳答案

对照列中的最后一个单元格检查单元格

  • 检查列 I 中最后一个非空单元格的值是否为工作表 Sheet2等于单元格 H22 中的值工作表 Sheet1并显示一个消息框。

  • Option Explicit

    Sub CheckCellAgainstLastCell()

    Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code

    Dim sws As Worksheet: Set sws = wb.Worksheets("Sheet2")
    Dim slCell As Range: Set slCell = sws.Cells(sws.Rows.Count, "I").End(xlUp)

    Dim dws As Worksheet: Set dws = wb.Worksheets("Sheet1")
    Dim dCell As Range: Set dCell = dws.Range("H22")

    If CStr(dCell.Value) = CStr(slCell.Value) Then
    MsgBox "It's a match.", vbInformation
    Else
    MsgBox "It's not a match.", vbCritical
    End If

    End Sub

    关于excel - 从表 1 和表 2 匹配或查找值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71291849/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com