2008年3月23日日曜日

マッチング

Dim chapter As String
Dim section As String
Dim subSection As String
Dim data As String
Dim lnIdxFrom As Integer
Dim lnIdxTo As Integer
Dim colIdx As Integer

Sub MatchData()
lnIdxFrom = 2
' シートTo
Sheets("To").Activate
maxlnTo = maxLine.maxLine(4)
' シートFrom
Sheets("From").Activate
maxlnFrom = maxLine.maxLine(4)

Do While lnIdxFrom <= maxlnFrom

chapter = Cells(lnIdxFrom, 1)
section = Cells(lnIdxFrom, 2)
subSection = Cells(lnIdxFrom, 3)

colIdx = 4

Do While Cells(lnIdxFrom, colIdx) <> ""

data = Cells(lnIdxFrom, colIdx)

' 対象シート検索
Sheets("To").Activate
lnIdxTo = 2

Do While lnIdxTo <= maxlnTo

If Cells(lnIdxTo, 4).Value = data Then
Cells(lnIdxTo, 5) = chapter
Cells(lnIdxTo, 6) = section
Cells(lnIdxTo, 7) = subSection
Exit Do
End If
lnIdxTo = lnIdxTo + 1
Loop

Sheets("From").Activate
colIdx = colIdx + 1
Loop

lnIdxFrom = lnIdxFrom + 1
Loop

End Sub

0 件のコメント: