【发布时间】:2017-05-31 16:11:51
【问题描述】:
我对 vba 很陌生,对于我在下面的代码中犯的(许多)错误,我深表歉意。当我设置 x 和 y 变量时出现错误,而且当我尝试运行索引和匹配组合时也出现错误。任何帮助将不胜感激!
Public Sub indexandmatch()
Dim x As Range
Dim y As Range
Dim mycells As Range
Dim p As Variant
'workbooks(1) is the master workbook where I am trying to get the information from the other reports to be entered in to
Application.Workbooks(1).Activate
x = Application.Workbooks(2).Worksheets(1).Range("H:H")
y = Application.Workbooks(2).Worksheets(1).Range("I:I")
'range v is where I would like the values to be entered in the master
For Each mycells In Range("V:V")
p = Application.WorksheetFunction.Index(x, Application.WorksheetFunction.Match(mycells.Offset(0, -11).Value, y), 0)
mycells = p.Value
Next
End Sub
【问题讨论】:
-
赋值对象变量时需要使用Set
-
“我收到错误”没有任何意义 - 您需要 edit 您的问题包含您遇到的具体错误,以及准确的在哪里 i> 在它发生的代码中。