单步执行代码或使用Run Sub / UserForm按钮,代码按预期运行。但是,当我使用命令按钮(分配了宏)时,代码会将数据粘贴到预先存在的数据上,而不是依据。
Sub Testing()
Application.ScreenUpdating = False
Dim tt As Range
Dim tt2 As Range
Dim LR As Long
Set tt = ThisWorkbook.Sheets("Table").UsedRange
Set tt2 = ThisWorkbook.Sheets("HAA").UsedRange
LR = Range("T" & Rows.Count).End(xlUp).Row
tt.AutoFilter
tt.AutoFilter 12, "already associated"
If Range("A1").Value <> "Notes" Then
tt.Copy
tt2.Range("B1").PasteSpecial xlPasteValues
tt2.Range("A1").Value = "Notes"
Else
If Range("A1").Value = "Notes" Then
tt.Offset(1, 0).Copy
With tt2
.Range("A" & LR).Offset(1, 1).PasteSpecial xlPasteValues
End With
End If
End If
With tt2
.AutoFilter
.Columns.AutoFit
.AutoFilter
End With
With tt2.Font
.Name = "Arial"
.Size = 8
End With
Application.ScreenUpdating = True
Sheets("HAA").Activate
End Sub
答案 0 :(得分:3)
执行时:
let g:ack_apply_qmappings = 0
您应告诉VBA是否使用表格(“表格”)或表格(“HAA”)
同样:
LR = Range("T" & Rows.Count).End(xlUp).Row