基于vba单元的特征创建动态范围
我想比较两个单元格的总和,这两个单元格的字体不是粗体,或者单元格内部的颜色是空的。我想比较这个列的单元格值的总和,只有当列的标签是“miercoles”、“jueves”、“viernes”或“sabado”时,这些单元格值才在一起,并且在查阅了第一个标签1、2、3和4的四个列之后,只对最大的结果着色。 我已经编写了这个代码,但是我没有在变量g中保存任何范围。 如何创建动态范围g基于vba单元的特征创建动态范围,vba,excel,dynamic,range,Vba,Excel,Dynamic,Range,我想比较两个单元格的总和,这两个单元格的字体不是粗体,或者单元格内部的颜色是空的。我想比较这个列的单元格值的总和,只有当列的标签是“miercoles”、“jueves”、“viernes”或“sabado”时,这些单元格值才在一起,并且在查阅了第一个标签1、2、3和4的四个列之后,只对最大的结果着色。 我已经编写了这个代码,但是我没有在变量g中保存任何范围。 如何创建动态范围g Sub reuniones_dos_horas() Dim r As Range Dim r2 As
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
Sub-reunions\u dos\u horas()
调光范围
变暗r2作为范围
a=2
而床单(“Dinamicos”)。单元格(27,a)”
b=1
而薄板(“Dinamicos”)。单元格(27,a)=f
e_range1=板材(“Dinamicos”)。范围(单元格(d,c),单元格(d+1,c))。选择
如果不是这样的话
f_range1=板材(“Dinamicos”)。范围(单元格(d+1,c)、单元格(d+2,c))。选择
如果结束
对于范围内的每个r2(单元(30,c),单元(44,c))
如果r2.Font.Underline=True,则
如果r什么都不是
设置r=范围(单元格(r2.Row,c))
其他的
集合r=并集(r,范围(单元格(r2.Row,c)))
如果结束
如果结束
下一个
h=工作表函数.Sum(ActiveRange)
g=工作表函数和(r)
如果h>=g,则
范围(列表)。激活
范围(列表)。Font.Underline=True
如果g>h,则
活动范围。选择
ActiceRange.Font.Underline=True
范围(列表)。Font.Underline=False
如果结束
如果结束
d=d+1
温德
如果结束
c=c+1
温德
b=b+1
温德
a=a+1
温德
端接头
如果有人需要做类似的事情,下面是我解决问题的方法
Sub reuniones_dos_horas()
Dim r As Range
Dim r2 As Range
Dim range1 As Range
Dim ra As Range
Dim W As Integer
Dim W0 As Integer
Dim ran As Range
Sheets("Dinamicos").Range("B30:LG44").Font.Underline = False
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.ColorIndex = xlNone And Sheets("Dinamicos").Cells(d, c).Interior.ColorIndex = 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 Sheets("Dinamicos").Cells(d, c).Interior.ColorIndex = xlNone And Sheets("Dinamicos").Cells(d + 1, c).Interior.ColorIndex = xlNone And Sheets("Dinamicos").Cells(d + 2, c).Interior.ColorIndex = xlNone Then
If e >= f Then
Set range1 = Union(Sheets("Dinamicos").Cells(d, c), Sheets("Dinamicos").Cells(d + 1, c))
ElseIf f > e Then
Set range1 = Union(Sheets("Dinamicos").Cells(d + 1, c), Sheets("Dinamicos").Cells(d + 2, c))
End If
For Each r2 In Range(Cells(30, c), Cells(44, c))
ver = r2.Row
ver2 = Cells(r2.Row, c)
If r2.Interior.ColorIndex = xlNone Then
If r2.Font.Underline = xlUnderlineStyleSingle Then
If r Is Nothing Then
Set r = Cells(r2.Row, c)
Else
Set r = Union(r, Cells(r2.Row, c))
End If
End If
End If
Next
g = WorksheetFunction.Sum(range1)
If r Is Nothing Then
h = g
Else
h = WorksheetFunction.Sum(r)
End If
If h >= g And r Is Nothing Then
range1.Font.Underline = True
Cells(47, c) = g
ElseIf h >= g Then
range1.Font.Underline = False
r.Font.Underline = True
Cells(47, c) = h
ElseIf g > h Then
r.Font.Underline = False
range1.Font.Underline = True
Cells(47, c) = g
End If
Set r = Nothing
End If
End If
d = d + 1
Wend
End If
c = c + 1
Wend
a1 = 1
b1 = 2
For a1 = 1 To 56 Step 4
'While a1 <= 50
While Sheets("Dinamicos").Cells(27, b1) < a1 + 3 And Sheets("Dinamicos").Cells(27, b1) <> ""
If a1 > 50 Then
Exit Sub
Else
W0 = Application.WorksheetFunction.CountIf(Range("B27:LG27"), "<" & a1)
W = Application.WorksheetFunction.CountIf(Range("B27:LG27"), "<=" & a1 + 3)
X = W - W0
y = X - 23
Y1 = y + 1
Y2 = 1 + W - 23
YY = Sheets("Dinamicos").Cells(47, 1 + W)
XX = Sheets("Dinamicos").Cells(47, Y1)
Set ra = Range(Cells(47, Y2), Cells(47, 1 + W))
AddressOfMax(ra).Interior.Color = RGB(0, 102, 204)
col = AddressOfMax(ra).Column
For Each rb In Range(Cells(30, col), Cells(44, col))
ver = rb.Row
ver2 = Cells(rb.Row, col)
If rb.Font.Underline = xlUnderlineStyleSingle Then
If ran Is Nothing Then
Set ran = Cells(rb.Row, col)
Else
Set ran = Union(ran, Cells(rb.Row, col))
End If
End If
Next
ran.Interior.Color = RGB(0, 102, 204)
b1 = b1 + 1
End If
Wend
b1 = 2
Next a1
'a1 = a1 + 4
'Wend
Call formato2
End Sub
Sub-reunions\u dos\u horas()
调光范围
变暗r2作为范围
变暗范围1作为范围
调光范围
作为整数的Dim W
作为整数的Dim W0
暗跑作为射程
工作表(“Dinamicos”).Range(“B30:LG44”).Font.Underline=False
c=2
而床单(“Dinamicos”)。单元格(29,c)”
Drev=板材(“Dinamicos”)。单元(29,c)
如果板材(“Dinamicos”)。单元(29,c)=“密孔”或
表(“Dinamicos”)。单元格(29,c)=“Jueves”或
表(“Dinamicos”)。单元格(29,c)=“Viernes”或
表(“Dinamicos”)。单元格(29,c)=“Sabado”然后
d=30
而薄板(“Dinamicos”)。单元(d+1,c)”
如果图纸(“Dinamicos”).单元格(d+1,c).Interior.ColorIndex=xlNone和图纸(“Dinamicos”).单元格(d,c).Interior.ColorIndex=xlNone和图纸(“Dinamicos”).单元格(d+1,c).Font.Bold=False和图纸(“Dinamicos”).单元格(d,c).Font.Bold=False,则
e=申请金额(表格(“迪纳米科斯”).单元格(d+1,c),表格(“迪纳米科斯”).单元格(d,c))
f=申请金额(表格(“迪纳米科斯”).单元格(d+1,c),表格(“迪纳米科斯”).单元格(d+2,c))
如果板材(“Dinamicos”).单元(d,c).Interior.ColorIndex=xlNone和板材(“Dinamicos”).单元(d+1,c).Interior.ColorIndex=xlNone和板材(“Dinamicos”).单元(d+2,c).Interior.ColorIndex=xlNone,则
如果e>=f,则
设置范围1=联合(板材(“Dinamicos”).单元(d,c),板材(“Dinamicos”).单元(d+1,c))
如果不是这样的话
设置范围1=联合(板材(“Dinamicos”).单元(d+1,c),板材(“Dinamicos”).单元(d+2,c))
如果结束
对于范围内的每个r2(单元(30,c),单元(44,c))
ver=r2.行
ver2=单元格(r2.Row,c)
如果r2.Interior.ColorIndex=xlNone,则
如果r2.Font.Underline=xlUnderlineStyleSingle,则
如果r什么都不是
设置r=单元格(r2.Row,c)
其他的
集合r=并集(r,单元格(r2.Row,c))
如果结束
如果结束
如果结束
下一个
g=工作表函数.Sum(范围1)
如果r什么都不是
h=g
其他的
h=工作表函数和(r)
如果结束
如果h>=g且r为零,则
range1.Font.Underline=True
单元(47,c)=g
ElseIf h>=g那么
range1.Font.Underline=False
r、 Font.Underline=True
单元(47,c)=h
如果g>h,则
r、 Font.Underline=False
range1.Font.Underline=True
单元(47,c)=g
如果结束
设置r=无
如果结束
如果结束
d=d+1
温德
如果结束
c=c+1
温德
a1=1
b1=2
对于a1=1至56,步骤4
“那么呢
出口接头
其他的
W0=Application.WorksheetFunction.CountIf(范围(“B27:LG27”),“如果有人需要做类似的事情,下面是我解决问题的方法
Sub reuniones_dos_horas()
Dim r As Range
Dim r2 As Range
Dim range1 As Range
Dim ra As Range
Dim W As Integer
Dim W0 As Integer
Dim ran As Range
Sheets("Dinamicos").Range("B30:LG44").Font.Underline = False
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.ColorIndex = xlNone And Sheets("Dinamicos").Cells(d, c).Interior.ColorIndex = 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 Sheets("Dinamicos").Cells(d, c).Interior.ColorIndex = xlNone And Sheets("Dinamicos").Cells(d + 1, c).Interior.ColorIndex = xlNone And Sheets("Dinamicos").Cells(d + 2, c).Interior.ColorIndex = xlNone Then
If e >= f Then
Set range1 = Union(Sheets("Dinamicos").Cells(d, c), Sheets("Dinamicos").Cells(d + 1, c))
ElseIf f > e Then
Set range1 = Union(Sheets("Dinamicos").Cells(d + 1, c), Sheets("Dinamicos").Cells(d + 2, c))
End If
For Each r2 In Range(Cells(30, c), Cells(44, c))
ver = r2.Row
ver2 = Cells(r2.Row, c)
If r2.Interior.ColorIndex = xlNone Then
If r2.Font.Underline = xlUnderlineStyleSingle Then
If r Is Nothing Then
Set r = Cells(r2.Row, c)
Else
Set r = Union(r, Cells(r2.Row, c))
End If
End If
End If
Next
g = WorksheetFunction.Sum(range1)
If r Is Nothing Then
h = g
Else
h = WorksheetFunction.Sum(r)
End If
If h >= g And r Is Nothing Then
range1.Font.Underline = True
Cells(47, c) = g
ElseIf h >= g Then
range1.Font.Underline = False
r.Font.Underline = True
Cells(47, c) = h
ElseIf g > h Then
r.Font.Underline = False
range1.Font.Underline = True
Cells(47, c) = g
End If
Set r = Nothing
End If
End If
d = d + 1
Wend
End If
c = c + 1
Wend
a1 = 1
b1 = 2
For a1 = 1 To 56 Step 4
'While a1 <= 50
While Sheets("Dinamicos").Cells(27, b1) < a1 + 3 And Sheets("Dinamicos").Cells(27, b1) <> ""
If a1 > 50 Then
Exit Sub
Else
W0 = Application.WorksheetFunction.CountIf(Range("B27:LG27"), "<" & a1)
W = Application.WorksheetFunction.CountIf(Range("B27:LG27"), "<=" & a1 + 3)
X = W - W0
y = X - 23
Y1 = y + 1
Y2 = 1 + W - 23
YY = Sheets("Dinamicos").Cells(47, 1 + W)
XX = Sheets("Dinamicos").Cells(47, Y1)
Set ra = Range(Cells(47, Y2), Cells(47, 1 + W))
AddressOfMax(ra).Interior.Color = RGB(0, 102, 204)
col = AddressOfMax(ra).Column
For Each rb In Range(Cells(30, col), Cells(44, col))
ver = rb.Row
ver2 = Cells(rb.Row, col)
If rb.Font.Underline = xlUnderlineStyleSingle Then
If ran Is Nothing Then
Set ran = Cells(rb.Row, col)
Else
Set ran = Union(ran, Cells(rb.Row, col))
End If
End If
Next
ran.Interior.Color = RGB(0, 102, 204)
b1 = b1 + 1
End If
Wend
b1 = 2
Next a1
'a1 = a1 + 4
'Wend
Call formato2
End Sub
Sub-reunions\u dos\u horas()
调光范围
变暗r2作为范围
变暗范围1作为范围
调光范围
作为整数的Dim W
作为整数的Dim W0
暗跑作为射程
工作表(“Dinamicos”).Range(“B30:LG44”).Font.Underline=False
c=2
而床单(“Dinamicos”)。单元格(29,c)”
Drev=板材(“Dinamicos”)。单元(29,c)
如果板材(“Dinamicos”)。单元(29,c)=“密孔”或
床单(“Dinamicos”)。单元格(29,c)=“Jue”