안녕,
섹션별로 행을 정렬하는 데 도움이 되는 VBA 코드를 만들었습니다. 아래를 참조하세요.
Sub ExtendOffice_Sort()
Dim xExtendRg, xOfficeSRgC As Range
Dim xRg As Range
Dim xRangeAddress As String
Dim xNum, xCSNum, xCENum, xRSNum, xRSNum2, xRENum As Integer
Dim xRCount As Integer
Dim xBol, xBolWS As Boolean
Dim xStr1, xStr2 As String
Dim xWSh As Worksheet
Dim xSortColumn As Integer
On Error Resume Next
Set xExtendRg = Application.InputBox("Please select the range with data to be sorted:", "ExtendOffice - Kutools for Excel", , , , , , 8)
If xExtendRg Is Nothing Then Exit Sub
Set xOfficeSRgC = Application.InputBox("Please select the column with values to be sorted from smallest to largest:", "ExtendOffice - Kutools for Excel", , , , , , 8)
If xOfficeSRgC Is Nothing Then Exit Sub
xNum = Application.InputBox("Please enter a number of rows to be sorted in a section:", "ExtendOffice - Kutools for Excel", , , , , , 1)
Set xRg = xExtendRg
Set xWSh = xRg.Worksheet
xWSh.Activate
xSortColumn = xOfficeSRgC.Column
xRCount = xRg.Rows.Count
xCSNum = xRg.Column
xCENum = xCSNum + xRg.Columns.Count - 1
xRSNum = xRg.Row
xRENum = xRSNum + xRCount - 1
xRSNum2 = xRSNum
xRSNum = (xRSNum + xNum) - 1
xBol = True
xBolWS = Application.ScreenUpdating
Application.ScreenUpdating = False
Do While xBol
xStr1 = xWSh.Cells(xRSNum2, xCSNum).Address & ":" & xWSh.Cells(xRSNum, xCENum).Address
xStr2 = xWSh.Cells(xRSNum2, xSortColumn).Address & ":" & xWSh.Cells(xRSNum, xSortColumn).Address
'Debug.Print xStr1 & " - " & xStr2
xWSh.Sort.SortFields.Clear
xWSh.Sort.SortFields.Add Key:=Range(xStr2) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With xWSh.Sort
.SetRange Range(xStr1)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
xWSh.Sort.SortFields.Clear
If (xRSNum + xNum) >= xRENum Then
If xRSNum = xRENum Then
xBol = False
Else
xRSNum2 = xRSNum + 1
xRSNum = xRENum
End If
Else
xRSNum2 = xRSNum + 1
xRSNum = (xRSNum + xNum)
End If
Loop
Application.ScreenUpdating = xBolWS
End Sub
그리고 최근에 제품 작업으로 바빴기 때문에 위의 코드가 "I" 셀의 최소 셀 Q 수와 공급업체 이름을 강조 표시하지 않은 점을 유감스럽게 생각합니다.
이해하길 바랍니다.
아만다