如何用VBA编程实现总课表自动填充到班课表中? VBA编程 vba公式自动双击填充

7710℃ KRISTI

如何用VBA编程实现总课表自动填充到班课表中? VBA编程vba公式自动双击填充

如何使用VBA进行公式自动填充?

输入完代码后,关闭VB编辑器即可。

Private Sub Worksheet_Change(ByVal Target As Range)

    x = Target.Row

    y = Target.Column

    If y = 1 Then

        If Cells(x, y) = "" Then

            Cells(x, y + 1).ClearContents

            Cells(x, y + 2).ClearContents

        ElseIf IsNumeric(Cells(x, y)) = True Then

            Cells(x, y + 1) = Cells(x, y) * 2

            Cells(x, y + 2) = Cells(x, y + 1) * 2

        End If

    End If

End Sub公式不管写在哪里,总得写出来吧,不然表格怎么知道你要怎么算。改了一下代码,你试试是不是这个效果。

Private Sub Worksheet_Change(ByVal Target As Range)

    x = Range("A" & Rows.Count).End(3).Row

    y = Target.Column

    If y = 1 Then

        Dim i As Long

        For i = 1 To x

            If Cells(i, y) = "" Then

                Cells(i, y + 1).ClearContents

                Cells(i, y + 2).ClearContents

            ElseIf IsNumeric(Cells(i, y)) = True Then

                Cells(i, y + 1) = Cells(i, y) * 2

                Cells(i, y + 2) = Cells(i, y + 1) * 2

            End If

        Next

    End If

End Sub嗯试试再说

vb程序设计——如何使单元格自动填充

Range("A9:A10").Select

Selection.AutoFill Destination:=Range("A9:A" & 10 + nx - 6 + 1), Type:=xlFillDefault

Range("B10").Select

Selection.AutoFill Destination:=Range("B10:B" & 10 + nx - 6 + 1), Type:=xlFillDefault

Range("C10").Select

Selection.AutoFill Destination:=Range("C10:C" & 10 + nx - 6 + 1), Type:=xlFillDefault

Range("D10").Select

Selection.AutoFill Destination:=Range("D10:D" & 10 + nx - 6 + 1), Type:=xlFillDefault

TAG: 课表 公式