|
* 답변하시는 분들께 도움이 되도록 자신의 환경을 아래 항목 옆에 기재해 주세요.
- 엑셀 버전(95,97,2000,xp,2003,2007):
* 아래줄에 질문을 작성하세요 >>
안녕하세요.. 엑셀에서 같은날 가장 이른시간의 데이터값
추출에 대한 질문입니다 ㅠ. 미리 감사말씀드립니다.
==============[장준화님 글에 대한 답변입니다]==============
위 조건은 함수로 처리하기는 어려운 상태인것 같네요...
아래 VBA를 모듈에 붙여넣고 실행해보세요.
Sub getScore()
Dim rData As Range, rRow As Range
Dim rTg As Range
Dim oDic As Object, oList As Object
Dim vKey, vGetA, vGetB
Dim vScore(1 To 2)
Dim iX As Integer
Set rData = Range("A1").CurrentRegion
rData.Sort Key1:=rData.Cells(1, 1), Key2:=rData.Cells(1, 2), Header:=xlYes
Set rData = rData.Offset(1).Resize(rData.Rows.Count - 1)
Set oDic = CreateObject("Scripting.Dictionary")
For Each rRow In rData.Rows
vKey = rRow.Cells(1, 1)
vGetA = rRow.Cells(1, 3)
vGetB = rRow.Cells(1, 4)
If vGetA = 0 Then
Else
If oDic.Exists(vKey) Then
If oDic.Item(vKey)(1) > vGetA Then vScore(1) = vGetA Else vScore(1) = oDic.Item(vKey)(1)
If oDic.Item(vKey)(2) < vGetB Then vScore(2) = vGetB Else vScore(2) = oDic.Item(vKey)(2)
oDic.Item(vKey) = vScore
Else
vScore(1) = vGetA
vScore(2) = vGetB
oDic.Add vKey, vScore
End If
End If
Next
Set rTg = Range("U2")
rTg.CurrentRegion.Clear
iX = 1
For Each vKey In oDic.keys
Debug.Print vKey, oDic.Item(vKey)(1), oDic.Item(vKey)(2)
rTg.Cells(iX, 1) = vKey
rTg.Cells(iX, 2) = oDic.Item(vKey)(1)
rTg.Cells(iX, 3) = oDic.Item(vKey)(2)
If iX > 1 Then rTg.Cells(iX - 1, 3) = oDic.Item(vKey)(1)
rTg.Cells(iX, 4) = "=RC[-1]-RC[-2]"
iX = iX + 1
Next
With rTg(0, 1).Resize(1, 4)
.Value = Split("날짜/누적점수/최종점수/획득점수", "/")
.HorizontalAlignment = xlCenter
.Interior.ColorIndex = 6
.CurrentRegion.Borders.LineStyle = xlContinuous
End With
End Sub
|
|