excel - VBA,对于每个应用程序匹配,需要对象

标签 excel vba

在应用程序匹配中循环出现问题。 我在 K.Offset(0, 1).Copy FV.Offset(2, 0)

行上收到错误 Object required

代码应该

1) 循环遍历 CS 范围,

2) 其中 CS 在 FV 范围内匹配,

3) 将 CS Offset(0,1) 处的单元格输入到 Offset(2,0) 上方的 FV 2 列中。

这是我的完整代码:

Sub n()

Dim FV As Variant
Dim CS As Variant
Dim K As Variant

FV = Sheets("NEW").Range("A28:A34").Value
CS = Sheets("CS").Range("A1:L1").Value

For Each K In CS
    If Not IsError(Application.Match(CS, FV, 0)) Then
        K.Offset(0, 1).Copy FV.Offset(2, 0)
        Else:
    End If
Next K

End Sub

最佳答案

您可以使用纯 VBA 函数,例如:

Sub CopyMatchingValues()
    Dim FV As Range
    Dim CS As Range
    Dim cellFV As Range
    Dim cellCS As Range

    Set FV = Sheets("NEW").Range("A28:A34")
    Set CS = Sheets("CS").Range("A1:L1")

    For Each cellCS In CS.Cells
        For Each cellFV In FV.Cells
            If cellFV.Value = cellCS.Value Then
                cellFV.Offset(2, 0).Value = cellCS.Offset(0, 1).Value
            End If
        Next
    Next
End Sub

关于excel - VBA,对于每个应用程序匹配,需要对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53450946/

相关文章:

excel - Application.WorksheetFunction.Match 没有按预期工作

c# - 如何从 DataTable 向 Excel 添加其他工作表

excel - 如何一次取消选中/选中所有复选框?

vba - 将所有命名范围提取到一个类中

c# - 如何禁用在选择任何单元格时停止计算的 Excel 2010 功能/错误?

excel - VB/A : Streaming data from Excel to PowerPoint

excel - 循环遍历范围内的每个单元格以确保它们的长度相同

regex - 如何在word中使用VBA(宏)使用/启用(RegExp对象)正则表达式

excel - 显示消息框时继续工作

vba - 将方程符号发送到 If 语句