|
本帖最后由 wc0606 于 2014-7-28 21:06 编辑
- '按照级别创建分组
- Sub My_Group()
- Dim LastRow, my_group_i, my_group_j As Integer
- Dim i, j, m, my_data As Integer
-
- LastRow = ActiveSheet.UsedRange.Rows.Count
- LastColumn = ActiveSheet.UsedRange.Columns.Count
- LastColumn_E = Split(ActiveSheet.Cells(LastRow, LastColumn).Address, "[ DISCUZ_CODE_0 ]quot;)(1)
- Set myrange = Application.InputBox("请选择分组依据所在列和首行数据所在行的交叉单元格:", "Make by wangc", Default:="$A$3", Type:=8)
- my_group_i = myrange.Row
- my_group_j = myrange.Column
-
- my_data = my_group_i
- n = 0
-
- Application.ScreenUpdating = False
-
- ActiveSheet.UsedRange.ClearOutline
-
- ActiveSheet.Select
- Cells.Select
- With Selection.Interior
- .Pattern = xlNone
- .TintAndShade = 0
- .PatternTintAndShade = 0
- End With
-
- For i = my_data To LastRow Step 1
- If ActiveSheet.Cells(i, my_group_j).Value = "" Then
- GoTo tuichu
- End If
- If ActiveSheet.Cells(i, my_group_j).Value < 8 Then
- For j = i + 1 To LastRow Step 1
- ' Debug.Print i
- m = ActiveSheet.Cells(j, my_group_j).Value - ActiveSheet.Cells(i, my_group_j).Value
- If m < -1 Then
- m = -1
- End If
- If m > 1 Then
- m = 1
- End If
-
- If j = LastRow And j - i >= 1 And m = 1 Then
- ActiveSheet.Rows(i + 1 & ":" & j).Group
- ActiveSheet.Range("A" & i & ":" & LastColumn_E & i).Interior.ThemeColor = xlThemeColorAccent6
- ActiveSheet.Range("A" & i & ":" & LastColumn_E & i).Interior.TintAndShade = 0.799981688894314
- Exit For
- Else
- Select Case m
- Case 1
-
- Case 0
- If j - i = 1 Then
- Exit For
- Else
- ActiveSheet.Rows(i + 1 & ":" & j - 1).Group
- ActiveSheet.Range("A" & i & ":" & LastColumn_E & i).Interior.ThemeColor = xlThemeColorAccent6
- ActiveSheet.Range("A" & i & ":" & LastColumn_E & i).Interior.TintAndShade = 0.799981688894314
- Exit For
- End If
- Case Else
- If j - i = 1 Then
- Exit For
- Else
- ActiveSheet.Rows(i + 1 & ":" & j - 1).Group
- ActiveSheet.Range("A" & i & ":" & LastColumn_E & i).Interior.ThemeColor = xlThemeColorAccent6
- ActiveSheet.Range("A" & i & ":" & LastColumn_E & i).Interior.TintAndShade = 0.799981688894314
- Exit For
- End If
- End Select
- End If
- Next j
- End If
- Next i
-
- With ActiveSheet.Outline
- .AutomaticStyles = False
- .SummaryRow = xlAbove
- .SummaryColumn = xlRight
- End With
-
- GoTo myok
-
- tuichu:
- MsgBox "出错了!"
- myok:
- ActiveSheet.Cells(1, 1).Select
- Application.ScreenUpdating = True
- End Sub
复制代码 这里有个问题,没能解决,希望看到的高人帮忙解决下。http://club.excelhome.net/thread-1140921-1-1.html |
|