0

在我的代码下面,以下行似乎存在问题:

Range("B4").Formula = "=index(C5:AV51,1,column(ActiveCell)-2)"

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False

For Each Cell In Range("C6:AV51")
Range("B4").Formula = "=index(C5:AV51,1,column(ActiveCell)-2)"

    If ActiveCell.Row - ActiveCell.Column < 3 Then
        ActiveCell.Formula = "=vlookup(index(B5:AV51,row()-4,1),'[" & Range("B4").Value & ".xlsx]Sheet1'!A1:E70,4,false)"

    ElseIf ActiveCell.Row - ActiveCell.Column = 3 Then
        ActiveCell.Value = ""
    Else
        ActiveCell.Formula = "=vlookup(index(B5:AV51,row()-4,1),'[" & Range("B4").Value & ".xlsx]Sheet1'!A1:E70,5,false)"
    End If
Next
    Application.EnableEvents = True    
End Sub
4

1 回答 1

1

ActiveCell是一个对象,所以替换所有实例

range("activecell")

ActiveCell

例子

if range("activecell").row - range("activecell").column < 3 then

变成

if ActiveCell.row - ActiveCell.column < 3 then

另一个错误,更改:

range("B4").formula = "=index(C5:AV51,1,column("activecell")-2)"

对此

range("B4").formula = "=index(C5:AV51,1," & ActiveCell.Column & ")-2)"
于 2013-06-24T11:09:10.387 回答