在EXCEL表中不改变单元格的数据顺序,逐个比较单元格里的数据大小,如何将"(22,34,53,99,99)、(1,12,,8)"等数据上升的区域和"(99,77,11)、(69,57,33,10)"等数据逐减的区域及数据重复区域(表中用深红色和浅红色标示的数字)求出来?并用不同的颜色表示数据上升、数据逐减、数据重复的区域。不知说明白没有?我试着做了一个,可是不行,现请大家帮忙解决一下,将万分感谢!EXCEL表见附件
Sub Cells()
Dim i, j, n, m, o As Integer
Dim A1 As Boolean: Dim A2 As Boolean
Dim B1 As Boolean: Dim B2 As Boolean
Dim Y As Integer
Cells() As Validation
o = 1
i = Sheet1.[a65536].End(xlUp).Row
For Y = 1 To 3
For j = o To i
If Cells(j, Y) >= Cells(j + 1, Y) Then
m = m + 1
n = 0
A1 = True: A2 = False
ElseIf Cells(j, Y) <= Cells(j + 1, Y) Then
A1 = False: A2 = True
m = 0
n = n + 1
Else
m = 0
n = 0
End If
If m = 0 Or n = 0 Then
If m >= 2 Then
Range(Cells(j - m + 1, Y), Cells(j + 1, Y)).Font.Color = vbRed
ElseIf n >= 2 Then
Range(Cells(j - n + 1, Y), Cells(j + 1, Y)).Font.Color = vbGreen
End If
End If
Next
Next
End Sub
Sub Cells()
Dim i, j, n, m, o As Integer
Dim A1 As Boolean: Dim A2 As Boolean
Dim B1 As Boolean: Dim B2 As Boolean
Dim Y As Integer
Cells() As Validation
o = 1
i = Sheet1.[a65536].End(xlUp).Row
For Y = 1 To 3
For j = o To i
If Cells(j, Y) >= Cells(j + 1, Y) Then
m = m + 1
n = 0
A1 = True: A2 = False
ElseIf Cells(j, Y) <= Cells(j + 1, Y) Then
A1 = False: A2 = True
m = 0
n = n + 1
Else
m = 0
n = 0
End If
If m = 0 Or n = 0 Then
If m >= 2 Then
Range(Cells(j - m + 1, Y), Cells(j + 1, Y)).Font.Color = vbRed
ElseIf n >= 2 Then
Range(Cells(j - n + 1, Y), Cells(j + 1, Y)).Font.Color = vbGreen
End If
End If
Next
Next
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货