これでいいんじゃないでしょうか。案はどれを選んでいるのか不明なので全て記載しています。A案が有効な状態だと思う(かなり忘れてるので)
Sub Test()
Dim c As Range, Fr As Range
Dim i As Long, mCount As Integer, SumCount As Integer
Dim oRow1 As Long, oRow2 As Long, oColumn1 As Long, oColumn2 As Long
Dim sData As Variant
Dim mRow As Long
''最初の案
'If Range("K10").Value = "コ" Then
' Range("K10").Value = "ア"
'ElseIf Range("K10").Value = "オ" Then
' Range("K10").Value = ChrW(AscW(Range("K10").Value) + 1)
'Else
' Range("K10").Value = ChrW(AscW(Range("K10").Value) + 2)
'End If
''もしくはのA案とB案
If Range("K9").Value = 9 Then
Range("K9").Value = 0
Else
Range("K9").Value = Range("K9").Value + 1
End If
'B案は↓が不要
Range("K10").Value = Range("AA10").Offset(0, Range("K9").Value).Value
'最後の案
'Set Fr = Range("AA10:AJ10").Find(What:=Range("K10").Value, LookIn:=xlValues, lookat:=xlWhole)
'If Not Fr Is Nothing Then
' If Fr.Address = Range("AJ10").Address Then
' Range("K10").Value = Range("AA10").Value
' Else
' Range("K10").Value = Fr.Offset(0, 1).Value
' End If
'Else
' MsgBox Range("K10").Value & "が見つかりません"
'End If
'Set Fr = Nothing
SumCount = 0
sData = Range("K10").Value
For i = 6 To 18 Step 3
For Each c In Range(Cells(i, "D"), Cells(i + 2, "G"))
If c.Value = sData Then
oRow1 = -2: oRow2 = 2
oColumn1 = -3: oColumn2 = 3
If c.Row = i Then
oRow1 = 0
ElseIf c.Row = i + 2 Then
oRow2 = 0
End If
If c.Column = Range("D:D").Column Then
oColumn1 = 0
ElseIf c.Column = Range("G:G").Column Then
oColumn2 = 0
End If
mCount = mSearch(c, oRow1, oColumn1, oRow2, oColumn2)
If mCount = 1 Then
SumCount = SumCount + mCount
Exit For
End If
End If
Next
Next
Set Fr = Range("AA10:AJ10").Find(What:=sData, LookIn:=xlValues, lookat:=xlWhole)
If Not Fr Is Nothing Then
mRow = Cells(Rows.Count, Fr.Column).End(xlUp).Offset(1, 0).Row
Cells(mRow, Fr.Column).Value = SumCount
Else
MsgBox sData & "が見つかりません"
End If
If SumCount = 2 Then
Call mSet(Range("S:S").Column, sData, mRow)
ElseIf SumCount > 2 Then
Call mSet(Range("M:M").Column, sData, mRow)
End If
End Sub
Function mSet(ByVal mColumn As Long, ByVal mData As Variant, mRow As Long)
Dim mCount As Integer
mCount = 6 - WorksheetFunction.CountBlank(Range(Cells(mRow, mColumn), Cells(mRow, mColumn).Offset(0, 5)))
Cells(mRow, mColumn).Offset(0, mCount).Value = mData
End Function
Function mSearch(ByRef d As Range, ByVal oRow1 As Long, ByVal oColumn1 As Long, ByVal oRow2 As Long, ByVal oColumn2 As Long) As Integer
Dim c As Range
For Each c In Range(d.Offset(oRow1, oColumn1), d.Offset(oRow2, oColumn2))
If c.Address <> d.Address And c.Row <> d.Row Then
If c.Value = d.Value Then
mSearch = 1
Exit Function
End If
End If
Next
mSearch = 0
End Function
お礼
そうなんですよw 下の方をカウントしてるみたいで、目的の所とは違う場所をカウントしてるようです。 今頑張ってソースをみなおしてます。(D6 : G20 )をカウントのフォーカスに定めるには何処から見直しが必要ですか?