0

我目前有这段代码来插入一个新行,对行中的第二个单元格使用验证:

Sub RICH()
'
' Macro3 Macro
   Dim ws As Worksheet
   Dim fnd As Range
   Dim fndstr As String

   fndstr = "Targeted Premium Ads"
   Set ws = Worksheets("Inputsheet")

        Set fnd = ws.Columns(2).Find(what:=fndstr, After:=ws.Range("B11"), _
        LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByColumns, _
        searchdirection:=xlNext, MatchCase:=False)

        If Not fnd Is Nothing Then

            Rows(fnd.Row - 1).Select
            Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
            Range("B" & fnd.Row - 2).Select
            With Selection.Validation
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                xlBetween, Formula1:="=Suppliers!$B$2:$B$178"
                .IgnoreBlank = True
                .InCellDropdown = True
                .InputTitle = ""
                .ErrorTitle = ""
                .InputMessage = ""
                .ErrorMessage = ""
                .ShowInput = True
                .ShowError = True



            End With
        End If
End Sub

但是,我现在想将两个函数,例如:=sum(A$4,B$5) 和 =sum(A$9,C$3) 分别插入这个新输出行的 N、O 列。什么是正确的方法?

4

1 回答 1

0

怎么样:

Range("N" & fnd.Row - 2).Formula = "=SUM(A$4,B$5)"
Range("O" & fnd.Row - 2).Formula = "=SUM(A$9,C$3)"

(假设fnd.Row - 2是您要放置公式的行)。

于 2013-01-21T17:30:30.357 回答