h行列校验

  1. h行列校验

h行列校验

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Sub 选行校验(control As IRibbonControl) '行列校验-选行校验
i = 0
x = 0
n = 0
If Selection.Type = wdSelectionColumn Then
For Each Acell In Selection.Cells '求所选列合计数
If Acell.ColumnIndex > n Then
n = Acell.ColumnIndex
End If
Set CR1 = ActiveDocument.Range(Acell.Range.Start, Acell.Range.End - 1)
If IsNumeric(CR1.Text) Then
i = CR1.Text + i
End If
Next
For Each Acell In Selection.Cells '求所选列最后一行合计数
Set CR2 = ActiveDocument.Range(Acell.Range.Start, Acell.Range.End - 1)
If Acell.ColumnIndex = n Then
If IsNumeric(CR2.Text) Then
x = CR2.Text + x
End If
End If
Next
P = i - x
q = P - x
y = "列校验:" & Format(P, "Standard") & "-" & Format(x, "Standard") & "=" & Format(q, "Standard")
Else
y = "只支持选中表格范围!"
End If
Application.StatusBar = y
End Sub
Sub 选列校验(control As IRibbonControl) '行列校验-选列校验
i = 0
x = 0
n = 0
If Selection.Type = wdSelectionColumn Then
For Each Acell In Selection.Cells '求所选列合计数
If Acell.RowIndex > n Then
n = Acell.RowIndex
End If
Set CR1 = ActiveDocument.Range(Acell.Range.Start, Acell.Range.End - 1)
If IsNumeric(CR1.Text) Then
i = CR1.Text + i
End If
Next
For Each Acell In Selection.Cells '求所选列最后一行合计数
Set CR2 = ActiveDocument.Range(Acell.Range.Start, Acell.Range.End - 1)
If Acell.RowIndex = n Then
If IsNumeric(CR2.Text) Then
x = CR2.Text + x
End If
End If
Next
P = i - x
q = P - x
y = "列校验:" & Format(P, "Standard") & "-" & Format(x, "Standard") & "=" & Format(q, "Standard")
Else
y = "只支持选中表格范围!"
End If
Application.StatusBar = y
End Sub
Sub 区域求和(control As IRibbonControl) '行列校验-区域求和
i = 0
If Selection.Type = 5 Then
For Each Acell In Selection.Cells
Set CR = ActiveDocument.Range(Acell.Range.Start, Acell.Range.End - 1)
If IsNumeric(CR.Text) Then
i = CR.Text + i
End If
Next
i = "合计:" & Format(i, "#,##0.00;-#,##0.00; ")
ElseIf Selection.Type = 4 Then
For Each Acell In Selection.Cells
Set CR = ActiveDocument.Range(Acell.Range.Start, Acell.Range.End - 1)
If IsNumeric(CR.Text) Then
i = CR.Text + i
End If
Next
i = "合计:" & Format(i, "#,##0.00;-#,##0.00; ")
Else
i = "只支持表格内行或列求和!"
End If
Application.StatusBar = i
End Sub

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 richffan@outlook.com

文章标题:h行列校验

字数:497

本文作者:Rich Fan

发布时间:2023-05-15, 00:00:00

最后更新:2024-02-27, 08:17:39

原始链接:http://fanrich.github.io/2023/05/14/VBA/%E5%BA%95%E7%A8%BF%E5%B0%8F%E5%B8%AE%E6%89%8B%E4%BB%A3%E7%A0%81/h%E8%A1%8C%E5%88%97%E6%A0%A1%E9%AA%8C/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。