Excel 특정셀 찾아서 셀이동후 지정셀 정렬하기
Sub 매크로1()
'
' 매크로1 매크로
'
'
Cells.Find(What:="보통소계", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, MatchByte:=False, SearchFormat:=False).Activate
Set rowNum = Range(ActiveCell.Address)
rowNum.Offset(-1, 0).Select ' 위로한칸이동
Dim adrSave As String
adrSave = ActiveCell.Address
' MsgBox adrSave
Range("A7").Select
ActiveCell.FormulaR1C1 = "=ROW()-6"
' Selection.AutoFill Destination:=Range("A7:A20")
Selection.AutoFill Destination:=Range("A7:" & adrSave) ' Range("A7:rowNum")
Cells.Find(What:="우1-00001", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, MatchByte:=False, SearchFormat:=False).Activate
ActiveCell.Range(Cells(1, 1), (Cells(5, 5))).Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range(ActiveCell.Address), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange ActiveCell.Range(Cells(1, 1), (Cells(5, 5)))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub