|
まず
>Sheet1に目次がありSheet2から表がある
ということなら、その見分け方を書いてもらいたかったのですが、いちおう
「先頭シートのE列に "イベントA" が見つからない場合は目次、そうでなければ
表のあるデータ」とみなすことにして
Sub Test_X()
Dim Ck As Variant
Dim Sti As Long, Mi As Long
Dim i As Long, j As Long
Dim TgR As Range, MyR1 As Range
Dim MyR2 As Range, MyR3 As Range
Ck = Application.Match("イベントA", Worksheets(1).Range("E:E"), 0)
If IsError(Ck) Then
Sti = 2
Else
Sti = 1
End If
For j = Sti To Worksheets.Count
Set TgR = _
Sheets(j).Range("E2", Sheets(j).Range("E65536").End(xlUp)) _
.Offset(, 26)
TgR.Formula = _
"=IF(LEFT($E2,5)=""イベント"",IF(RIGHT($E2,1)=""A"",FALSE,#N/A),"""")"
On Error GoTo NLine
Set MyR1 = TgR.SpecialCells(3, 4)
Set MyR2 = TgR.SpecialCells(3, 16)
On Error GoTo 0
Mi = Application.Min(MyR1.Count, MyR2.Count)
For i = 1 To Mi
MyR1.Areas(i).Offset(, -25).Resize(, 2).Value = _
Array("○○", "○○○")
Set MyR3 = Range(MyR1.Areas(i), MyR2.Areas(i)).Offset(, -26)
If WorksheetFunction.CountBlank(MyR3) > 0 Then
With MyR3.SpecialCells(4)
.Offset(, -1).ClearContents
.EntireRow.Interior.ColorIndex = 16
End With
End If
Set MyR3 = Nothing
Next i
NLine:
TgR.ClearContents
Set TgR = Nothing: Set MyR1 = Nothing: Set MyR2 = Nothing
If Err.Number <> 0 Then Err.Clear
Next j
End Sub
|
|