ためしに作ったものです。
販売伝票などのエクセルの表を、商品ごとに色分けして、なんとなく売れ筋が見えてくるというものを考えました。
商品コードごとにセルを塗りつぶすだけという単純なものです。
※アクティブワークシートのA列に商品コードがあると想定して検索します
※アクティブワークシートのA列からE列のみ色付けします
※アクティブワークシートの101行目以降は商品マスタテーブルをおきます
Sub cellcolor()
'gyoとretsuを整数型として定義
Dim gyo As Integer
Dim retsu As Integer
'hinmokuを長整数型として定義
Dim hinmoku As Long
'hinmokucodestartを整数型として定義
Dim hinmokucodestart As Integer
'最初の行は標題なので2行目から一行ずつ検索していきます
For gyo = 2 To 200
'各行の、A列からE列を検索します
For retsu = 1 To 5
'その行の品目コードを取得
hinmoku = Cells(gyo, 1).Value
'>>>商品マスタの開始する行をココに入力する>>>
hinmokucodestart = 101
Select Case hinmoku
'各行の品目をシートの101行目以降の商品マスタの品目コードから区別し
'品目毎にセルを色づけします。インデックス番号ごとに色が変わります
'品目は16種類です。追加があるときは下に加えていきます
Case Is = Cells(hinmokucodestart + 0, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 1
Case Is = Cells(hinmokucodestart + 1, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 2
Case Is = Cells(hinmokucodestart + 2, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 3
Case Is = Cells(hinmokucodestart + 3, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 4
Case Is = Cells(hinmokucodestart + 4, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 5
Case Is = Cells(hinmokucodestart + 5, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 6
Case Is = Cells(hinmokucodestart + 6, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 7
Case Is = Cells(hinmokucodestart + 7, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 8
Case Is = Cells(hinmokucodestart + 8, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 9
Case Is = Cells(hinmokucodestart + 9, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 10
Case Is = Cells(hinmokucodestart + 10, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 11
Case Is = Cells(hinmokucodestart + 11, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 12
Case Is = Cells(hinmokucodestart + 12, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 13
Case Is = Cells(hinmokucodestart + 13, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 14
Case Is = Cells(hinmokucodestart + 14, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 15
Case Is = Cells(hinmokucodestart + 15, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 16
Case Is = Cells(hinmokucodestart + 16, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 17
End Select
'retsuを1加えてE列まで繰り返し
Next retsu
'gyoを200行まで繰り返し
Next gyo
End Sub
販売伝票などのエクセルの表を、商品ごとに色分けして、なんとなく売れ筋が見えてくるというものを考えました。
商品コードごとにセルを塗りつぶすだけという単純なものです。
※アクティブワークシートのA列に商品コードがあると想定して検索します
※アクティブワークシートのA列からE列のみ色付けします
※アクティブワークシートの101行目以降は商品マスタテーブルをおきます
Sub cellcolor()
'gyoとretsuを整数型として定義
Dim gyo As Integer
Dim retsu As Integer
'hinmokuを長整数型として定義
Dim hinmoku As Long
'hinmokucodestartを整数型として定義
Dim hinmokucodestart As Integer
'最初の行は標題なので2行目から一行ずつ検索していきます
For gyo = 2 To 200
'各行の、A列からE列を検索します
For retsu = 1 To 5
'その行の品目コードを取得
hinmoku = Cells(gyo, 1).Value
'>>>商品マスタの開始する行をココに入力する>>>
hinmokucodestart = 101
Select Case hinmoku
'各行の品目をシートの101行目以降の商品マスタの品目コードから区別し
'品目毎にセルを色づけします。インデックス番号ごとに色が変わります
'品目は16種類です。追加があるときは下に加えていきます
Case Is = Cells(hinmokucodestart + 0, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 1
Case Is = Cells(hinmokucodestart + 1, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 2
Case Is = Cells(hinmokucodestart + 2, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 3
Case Is = Cells(hinmokucodestart + 3, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 4
Case Is = Cells(hinmokucodestart + 4, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 5
Case Is = Cells(hinmokucodestart + 5, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 6
Case Is = Cells(hinmokucodestart + 6, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 7
Case Is = Cells(hinmokucodestart + 7, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 8
Case Is = Cells(hinmokucodestart + 8, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 9
Case Is = Cells(hinmokucodestart + 9, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 10
Case Is = Cells(hinmokucodestart + 10, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 11
Case Is = Cells(hinmokucodestart + 11, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 12
Case Is = Cells(hinmokucodestart + 12, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 13
Case Is = Cells(hinmokucodestart + 13, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 14
Case Is = Cells(hinmokucodestart + 14, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 15
Case Is = Cells(hinmokucodestart + 15, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 16
Case Is = Cells(hinmokucodestart + 16, 1).Value
Cells(gyo, retsu).Interior.ColorIndex = 17
End Select
'retsuを1加えてE列まで繰り返し
Next retsu
'gyoを200行まで繰り返し
Next gyo
End Sub