假设你的数据表名为 Sheet1
打开你的EXCEL文件,按 ALL+F11 键,双击左面的Sheet1(Sheet1),进入VBA代码窗口,把下面的代码复制到代码窗口。
回到数据表Sheet1,请试试在A1:AU1任何一个单元格修改数据。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MaxL As Integer
'获取当前数据最大行号
MaxL = Excel.Application.ActiveWorkbook.Sheets("Sheet1").Range("A65535").End(xlUp).Row
If Not Intersect(Target, [a1:au1]) Is Nothing Then
For i = 1 To 47
If Excel.Application.ActiveWorkbook.Sheets("Sheet1").Cells(1, i).Value <> Excel.Application.ActiveWorkbook.Sheets("Sheet1").Cells(MaxL, i).Value Then
MaxL = MaxL + 1
Excel.Application.ActiveWorkbook.Sheets("Sheet1").Range("A" & CStr(MaxL) & ":AU" & CStr(MaxL)).Value = _
Excel.Application.ActiveWorkbook.Sheets("Sheet1").Range("A1:AU1").Value
Exit Sub
End If
Next i
End If
End Sub
x = Cells(Rows.Count, 1).End(xlUp).Row + 1
Range("A1:AU1").Copy Cells(x, 1)
发你的文件来,我能写