我想知道是否有任何方法可以检测到%的列?之后,将具有%?
的行相加例如,在下面,我有一张图片,列B -D的值为%。 B中的总百分比为130%,C为105%,D为90%。总数将放在后面的空行中,对于这个特定的例子,将是第8行。我需要该行是灵活的,因为它最终可能超过8行。
我希望有人理解我在这里要传达的内容。我想要做的是寻找%并总结它们,总数将被放置在随后的空行中。
答案 0 :(得分:2)
我不理解第1栏中关于百分比的后续问题。以下是我对原始问题的解决方案。它在任何现有行下方创建一行,其中包含列中任何百分比的总和。我已经格式化了这些值,然后用蓝色来表示颜色。我已经在评论中说明了我在做什么,但没有解释为什么声明会做它的作用。首先尝试VBA帮助,然后回答任何问题。
Option Explicit
Sub SumPercentages()
Dim ColCrnt As Long
Dim ColCrntMax As Long
Dim ColMax As Long
Dim RowCrnt As Long
Dim RowCrntMax As Long
Dim RowSum As Long
Dim TotalPerc As Double
With Sheets("Sheet1") ' Replace with name of your sheet
' Find the last used row plus one as the row on which to place
' the totals. Warning, this statement will throw an error if
' there is a value on the last possible row.
RowSum = .Cells.SpecialCells(xlCellTypeLastCell).Row + 1
' Find the last used column
ColMax = .Cells.SpecialCells(xlCellTypeLastCell).Column
' Examine every used column
For ColCrnt = 1 To ColMax
' Find the last used row in this column
RowCrntMax = .Cells(Rows.Count, ColCrnt).End(xlUp).Row
TotalPerc = 0
' Examine each row of this column
For RowCrnt = 1 To RowCrntMax
If Right(.Cells(RowCrnt, ColCrnt).NumberFormat, 1) = "%" Then
TotalPerc = TotalPerc + Val(.Cells(RowCrnt, ColCrnt).Value)
End If
Next
' Save the value, format as percentage, colour blue
With .Cells(RowSum, ColCrnt)
.Value = TotalPerc
.NumberFormat = "0%"
.Font.Color = RGB(0, 0, 255)
End With
Next
End With
End Sub