備忘録

とにかく、メモガキ。思いついたらメモ

セルを、種類ごとに自動的に色分けするVBAモジュール案

2005-04-28 12:48:21 | Weblog
ためしに作ったものです。
販売伝票などのエクセルの表を、商品ごとに色分けして、なんとなく売れ筋が見えてくるというものを考えました。
商品コードごとにセルを塗りつぶすだけという単純なものです。

※アクティブワークシートの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


CoRichブログランキング

EXCELやACCESSのVBA 初心者知識

2005-04-28 12:08:57 | Weblog
エクセル、アクセスのVBAを練習中のため、覚えて言ったことをメモしていこうと思う。
思っても続かないのが俺らしいが。。。。

ちょー初心者的なところで
if ~ then ~ else ~
という構文は、エクセルの関数と同様に使用できるけれども
最後に
end ifで括ってやらないと、エラーになります。
なりました。



CoRichブログランキング

オフィスのワードやパワーポイント(パワポ)でうんともすんともいわないとき

2005-04-27 16:28:07 | Weblog
Ms-office2003のwordとPowerpointで発生した事象の回復方法を記録しておきます。
[事象]正常なファイルであるにもかかわらず、文字を入力しようとするとCPU使用率が100%となりフリーズ同然の状態となる。新規ファイルでも同様。MS-officeの再インストールでは解消しない。メモ帳、ワードパッド、EXCELなどのソフトでは正常に入力できる
[解決方法]MS-IMEのプロパティを開き、辞書/学習のタブのユーザー辞書の「参照」をクリック。「imjp9u1.dic」などの存在しないファイル名で「開く」をクリック。
以上で直りました。

要するにユーザー辞書のデータが何らかの理由で壊れてしまったのだと思われます。が、ユーザー辞書の「修復」では復活できません。同様にCPU100%となります。
また、ユーザー辞書がまっさらになりますので、覚えさせたものはなくなってしまいます


CoRichブログランキング