背景
问题
在“可交付成果”和“会议”表的表中添加新行时,代码和宏运行良好,但是当我在“关键联系人” RACI表中的表中添加行时,出现错误:
运行时错误1004 Range类的自动填充方法失败。
这是问题所在,由于某种原因,而不是Marco为Key Contacts表运行,而是以某种方式尝试为Deliverables表运行宏,或者至少是调试将我带到该宏。
代码显示在这里:
Private Sub Worksheet_Calculate()
'This code will auto run given macro when the formula results in the cell changes
Static OldVal As Variant
If Range("C3").Value <> OldVal Then
OldVal = Range("C3").Value
Call Macro2 'this updates the IDs on the Key Contacts and RACI tab
Application.ErrorCheckingOptions.BackgroundChecking = False
End If
End Sub
Sub Macro2()
Range("B5").Select
Selection.AutoFill Destination:=Range("Table7[ID]")
Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
Dim currentRowValue As String
sourceCol = 4 'column d has a value of 4
rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row
'for every row, find the first blank cell and select it
For currentRow = 5 To rowCount
currentRowValue = Cells(currentRow, sourceCol).Value
If IsEmpty(currentRowValue) Or currentRowValue = "" Then
Cells(currentRow, sourceCol).Select
End If
Next
End Sub
请注意,它应运行的宏是Macro2,应更新的表是Table9
我对这个很迷失。
代码和宏的图片:Images of code and macro