Const rowMax = 200
Const colMax = 23
Sub test()
'チェックする色のインデックス値を調べておく
checkColorIndex = Range("A1").Interior.ColorIndex
'MsgBox checkColorIndex 黄色:6
For y = 8 To rowMax
'c列に何も記述されてない行まで来たら処理を終わらす
If Cells(y, 3).Value = "" Then
MsgBox "8-" & y & "行まで処理を実行します"
Exit For
End If
'シート3のD列以降を一旦クリア
For x = 4 To colMax
Sheet3.Cells(y, x).Value = ""
Next x
tmpX = 4 '見つかった値をシート3の何列目に記述するかの値
'シート1のセルに色がついてるかをチェック
For x = 4 To colMax
If Cells(y, x).Interior.ColorIndex = checkColorIndex Then
'色のついているセルを発見
Sheet3.Cells(y, tmpX).Value = Cells(y, x).Value
'もし同じ行に色のついているセルが2個以上あった場合
'シート2の書きこむ列を一つ右へずらす
tmpX = tmpX + 1
End If
Next x
Next y
End Sub
Const rowStart = 8
'初めに何行目まで処理するかを調べる
For y = rowStart To rowMax
If Cells(y, 1).Value = "" And Cells(y + 1, 1).Value = "" Then
lastRow = y - 1
MsgBox rowStart & "-" & (lastRow - 1) & "行まで処理を実行します"
Exit For
End If
Next y
For i = 1 To ThisWorkbook.Sheets.Count
tmpSheetName = ThisWorkbook.Sheets(i).Name
If Left(tmpSheetName, 1) = "D" Then
DSheetName = tmpSheetName
Exit For
End If
Next i
If DSheetName = "" Then
MsgBox "シートが見つかりません"
Else
MsgBox DSheetName
End If