发布网友 发布时间:2022-05-11 22:54
共1个回答
热心网友 时间:2023-10-24 00:39
方式一:打开Excel文档,选中需要求和的区域,在Excel的右下角立即就会显示一个求和值。追答按alt+f11进vba编辑,双击thisworkbook,贴上以下代码
Option Explicit
Sub color()
Dim isnum As Boolean
Dim c, r, i, j As Integer
i = 1
j = 1
' 循环选择的每一行。
For r = 1 To Selection.Rows.Count
' 循环选择的每一列。
For c = 2 To Selection.Columns.Count
If Selection.Cells(r, c).Text = Selection.Cells(r, c - 1).Text Then
i = i + 1
Else
Cells(Selection.Cells(r, c).Row, Selection.Columns.Count + j).Value = i
i = 1
j = j + 1
End If
' Selection.Cells(r, c).Interior.ColorIndex = ci
Next c
Cells(Selection.Cells(r, c).Row, Selection.Columns.Count + j).Value = i
i = 1
j = 1
Next r
End Sub
关闭vba后,选中数值范围,按Alt+f8执行宏