1
Sheets("DATA").Rows(2).Find(What:="Apple", LookIn:=xlValues, _
                                  LookAt:=xlWhole).Offset(1, 0).Value = "=A3-B3"
                                  Selection.FillDown

我想在第 2 行中找到一列“Apple”并填写公式“A3-B3”这样的
东西有用.value="=A3-B3".filldown吗?
谢谢!

4

1 回答 1

2

除了我上面的评论,试试这个。我已经评论了代码。如果您发现任何令人困惑的事情,请告诉我...

Sub Sample()
    Dim ws As Worksheet
    Dim LRow As Long
    Dim aCell As Range

    '~~> Set this to the relevant sheet
    Set ws = ThisWorkbook.Sheets("Data")

    With ws
        '~~> Find Last Row
        LRow = .Range("A" & .Rows.Count).End(xlUp).Row

        '~~> Find the cell which has "Apple"
        Set aCell = .Rows(2).Find(What:="Apple", LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)

        '~~> if found, then enter the formula till the last row IN ONE GO
        If Not aCell Is Nothing Then
            .Range(.Cells(3, aCell.Column), .Cells(LRow, aCell.Column)).Formula = "=A3-B3"
        End If
    End With
End Sub
于 2013-09-16T17:09:04.067 回答