[VBA]事件记事本

需求

在excel中记录的事件 都汇总到某一个单元格中;

实施

使用vba

实现将 startRow 和 startColumn 开始的一行数据都统计到 首列中;

Sub collect()
    Dim str As String
    Dim startRow, maxRow As Integer
    Dim startColumn, maxColumn As Integer
    
    Dim i, j As Integer
    startRow = 2
    maxRow = 10
    startColumn = 6
    maxColumn = 20
    
    For i = startRow To maxRow
    
        str = ""
        For j = startColumn To maxColumn
            If Cells(i, j + 1) <> "" Then
            str = str + Cells(1, j + 1).Text + ":" + Cells(i, j + 1).Text + Chr(10)
            End If
        Next
        Cells(i, startColumn) = str
    Next

End Sub

其他

文件如果需要保存vba,需要另存为 xlsm类型的文件

你可能感兴趣的:(啥玩意,excel)