【发布时间】:2017-11-10 12:00:42
【问题描述】:
我想比较两个非粗体或单元格内部颜色为空的单元格的总和。我想比较只有当列的标签是“miercoles”、“jueves”、“viernes”或“sabado”时列的单元格值的总和,并且只是在咨询四列后着色最大的结果对于第一个标签 1、2、3 和 4。 我已经编写了这段代码,但我没有在变量 g 中保存任何范围。 如何创建动态范围 g?
Sub reuniones_dos_horas()
Dim r As Range
Dim r2 As Range
a = 2
While Sheets("Dinamicos").Cells(27, a) <> ""
b = 1
While Sheets("Dinamicos").Cells(27, a) <= b + 3
c = 2
While Sheets("Dinamicos").Cells(29, c) <> ""
Drev = Sheets("Dinamicos").Cells(29, c)
If Sheets("Dinamicos").Cells(29, c) = "Miercoles" Or Sheets("Dinamicos").Cells(29, c) = "Jueves" Or Sheets("Dinamicos").Cells(29, c) = "Viernes " Or Sheets("Dinamicos").Cells(29, c) = "Sabado" Then
d = 30
While Sheets("Dinamicos").Cells(d + 1, c) <> ""
If Sheets("Dinamicos").Cells(d + 1, c).Interior.Pattern = xlNone And Sheets("Dinamicos").Cells(d, c).Interior.Pattern = xlNone And Sheets("Dinamicos").Cells(d + 1, c).Font.Bold = False And Sheets("Dinamicos").Cells(d, c).Font.Bold = False Then
e = Application.Sum(Sheets("Dinamicos").Cells(d + 1, c), Sheets("Dinamicos").Cells(d, c))
f = Application.Sum(Sheets("Dinamicos").Cells(d + 1, c), Sheets("Dinamicos").Cells(d + 2, c))
If e >= f Then
e_range1 = Sheets("Dinamicos").Range(Cells(d, c), Cells(d + 1, c)).Select
ElseIf f > e Then
f_range1 = Sheets("Dinamicos").Range(Cells(d + 1, c), Cells(d + 2, c)).Select
End If
For Each r2 In Range(Cells(30, c), Cells(44, c))
If r2.Font.Underline = True Then
If r Is Nothing Then
Set r = Range(Cells(r2.Row, c))
Else
Set r = Union(r, Range(Cells(r2.Row, c)))
End If
End If
Next
h = WorksheetFunction.Sum(ActiveRange)
g = WorksheetFunction.Sum(r)
If h >= g Then
Range(List).Activate
Range(List).Font.Underline = True
ElseIf g > h Then
ActiveRange.Select
ActiceRange.Font.Underline = True
Range(List).Font.Underline = False
End If
End If
d = d + 1
Wend
End If
c = c + 1
Wend
b = b + 1
Wend
a = a + 1
Wend
End Sub
【问题讨论】: