【发布时间】:2015-01-26 03:19:34
【问题描述】:
我有 2 张纸。当 ws2 中特定列中的条目包含单词“UPDATE”时,它将使用 ws2 中找到的更新数据更新 ws1
Private Sub CommandButton1_Click()
Dim LastRow As Long, CurRow As Long, DestRow As Long, DestLast As Long
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Sheets("Dashboard")
Set ws2 = Sheets("TempHRI")
LastRow = ws2.Range("B" & Rows.Count).End(xlUp).Row
DestLast = ws1.Range("E" & Rows.Count).End(xlUp).Row
For CurRow = 2 To LastRow 'Assumes first row has headers
If ws2.Range("X" & CurRow) = "UPDATE" Then 'Column that looks up the word "Update" in ws2
If Not ws1.Range("E15:E" & DestLast).Find(ws2.Range("B" & CurRow).Value, LookIn:=xlValues, LookAt:=xlWhole) Is Nothing Then
DestRow = ws1.Range("E15:E" & DestLast).Find(ws2.Range("B" & CurRow).Value, LookIn:=xlValues, LookAt:=xlWhole).Row
End If
ws1.Range("Q" & DestRow).Value = ws2.Range("N" & CurRow).Value 'assumes supervisor is in column C in both sheets
ws1.Range("R" & DestRow).Value = ws2.Range("O" & CurRow).Value 'assumes director is in column D in both sheets
End If
Next CurRow
End Sub
但我在网上遇到类型不匹配:
If ws2.Range("X" & CurRow) = "UPDATE" Then
提前致谢。
【问题讨论】:
标签: vba excel type-mismatch