No.2ベストアンサー
- 回答日時:
こんばんは!
No.1さんのお礼欄に
>日付を自動で認識して交互に行の色分けができるとありがたいです・・・
とありますので、お邪魔します。
一例です。
1行目はタイトル行でデータは2行目以降にあるとします。
B列データは昇順に並んでいるとして、
Sub 色分け()
Dim i As Long
Dim j As Long
Application.ScreenUpdating = False
Cells.Interior.ColorIndex = xlNone
j = Cells(1, Columns.Count).End(xlToLeft).Column
Cells(2, 1).Resize(1, j).Interior.ColorIndex = 36 '←薄い黄色にしています。
For i = 3 To Cells(Rows.Count, 1).End(xlUp).Row
If Cells(i, 2) = Cells(i - 1, 2) Then
With Cells(i, 1).Resize(1, j)
.Interior.ColorIndex = .Offset(-1).Interior.ColorIndex
End With
ElseIf Cells(i - 1, 1).Interior.ColorIndex = xlNone Then
Cells(i, 1).Resize(1, j).Interior.ColorIndex = 36
End If
Next i
Application.ScreenUpdating = True
End Sub
こんな感じではどうでしょうか?m(_ _)m
No.3
- 回答日時:
こんな感じ、、、???、、、
Option Explicit
Sub HighlightHeavy()
Const xKey_Row = 2
Const xKey_Col = "B"
Const xBlack = 1
Const xWhite = 2
Const xBlue = 5
Const xYellow = 6
Dim kk As Long
Dim nn As Long
Dim xBefre As Boolean
Dim xLast As Long
Dim xRight As Long
xLast = Cells(Rows.Count, xKey_Col).End(xlUp).Row
xRight = Cells(1, Columns.Count).End(xlToLeft).Column
If (xLast <= xKey_Row) Or (xRight < Range(xKey_Col & "1").Column) Then
MsgBox ("No Data Found!!")
Exit Sub
End If
For nn = xKey_Row To xLast
'日付は文字列でもOK?
If (Cells(nn, xKey_Col).Value = Cells(nn + 1, xKey_Col).Value) And (Cells(nn, xKey_Col).Value <> Empty) Then
'どちらもハイライト
For kk = 1 To xRight
Cells(nn, kk).Font.Bold = True
Cells(nn, kk).Font.ColorIndex = xYellow
Cells(nn, kk).Interior.ColorIndex = xBlue
Next kk
xBefre = True
Else
If (xBefre) Then
'直前一致あり:借りを返済
For kk = 1 To xRight
Cells(nn, kk).Font.Bold = True
Cells(nn, kk).Font.ColorIndex = xYellow
Cells(nn, kk).Interior.ColorIndex = xBlue
Next kk
xBefre = False
Else
'前の状態に関係なくリセット
For kk = 1 To xRight
Cells(nn, kk).Font.Bold = False
Cells(nn, kk).Font.ColorIndex = xBlack
Cells(nn, kk).Interior.ColorIndex = xWhite
Next kk
End If
End If
Next nn
End Sub
No.1
- 回答日時:
例えば、
Option Explicit
Sub HighlightHeavy()
Const xKey_Row = 2
Const xKey_Col = "B"
Const xBlack = 1
Const xWhite = 2
Const xBlue = 5
Const xYellow = 6
Dim kk As Long
Dim nn As Long
Dim xLast As Long
Dim xRight As Long
xLast = Cells(Rows.Count, xKey_Col).End(xlUp).Row
xRight = Cells(1, Columns.Count).End(xlToLeft).Column
For nn = xKey_Row To xLast
Select Case Cells(nn, xKey_Col).Value
Case "20120905"
For kk = 1 To xRight
Cells(nn, kk).Font.Bold = True
Cells(nn, kk).Font.ColorIndex = xYellow
Cells(nn, kk).Interior.ColorIndex = xBlue
Next kk
Case Else
For kk = 1 To xRight
Cells(nn, kk).Font.Bold = False
Cells(nn, kk).Font.ColorIndex = xBlack
Cells(nn, kk).Interior.ColorIndex = xWhite
Next kk
End Select
Next nn
End Sub
この回答へのお礼
お礼日時:2012/11/20 14:52
回答ありがとうございます。
説明不足で申し訳ありません。
データが1000行以上あるため、日付を自動で認識して交互に行の色分けができるとありがたいです。質問の表では、A2:C3、A4:C4、A5:C6、A7:C7を交互に色分けになります。お手数ですが、この条件に対応できるようにしていただけますでしょうか。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・【お題】絵本のタイトル
- ・【大喜利】世界最古のコンビニについて知ってる事を教えてください【投稿~10/10(木)】
- ・メモのコツを教えてください!
- ・CDの保有枚数を教えてください
- ・ホテルを選ぶとき、これだけは譲れない条件TOP3は?
- ・家・車以外で、人生で一番奮発した買い物
- ・人生最悪の忘れ物
- ・【コナン30周年】嘘でしょ!?と思った○○周年を教えて【ハルヒ20周年】
- ・ハマっている「お菓子」を教えて!
- ・最近、いつ泣きましたか?
- ・夏が終わったと感じる瞬間って、どんな時?
- ・10秒目をつむったら…
- ・人生のプチ美学を教えてください!!
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・都道府県穴埋めゲーム
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
アクセス2003で、数値のプロパ...
-
Accessの桁区切りについ...
-
アクセス データエクスポート...
-
アクセス集計クエリでの書式設定
-
Accessでの入力規則について
-
「年」と「月」だけの日付の表...
-
Access2000のレポートで小数点...
-
ユニオンクエリの書式について
-
ワードで入力できる文字数を制...
-
アクセス クエリ 時間の合計
-
Access テキスト型を日付/時刻...
-
ACCESS 日付型でEXCEL出力
-
Word2010の差込印刷で金額にコ...
-
差込印刷での全角表示について...
-
日付型のフィールドに空白を入...
-
SQL文で パラメータが少なすぎ...
-
エクセルにおける「フィールド...
-
エクセルデータをワードで差し...
-
アクセスで追加した項目に全て...
-
アクセスのエラー「クエリには...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
Accessの桁区切りについ...
-
「年」と「月」だけの日付の表...
-
アクセス データエクスポート...
-
Word2010の差込印刷で金額にコ...
-
アクセスのクエリで秒→時間、時...
-
フォーム データシートビューで...
-
アクセスのフォームで、桁数を...
-
Access2013にてハイパーリンク...
-
アクセス クエリ 時間の合計
-
ワードで入力できる文字数を制...
-
Access テキスト型を日付/時刻...
-
【Access2003】書式設定(Forma...
-
Accessでの入力規則について
-
アクセス集計クエリでの書式設定
-
ACCESSで、コンマを付けてCSVを...
-
アクセスで西暦データを和暦表...
-
ユニオンクエリの書式について
-
ACCESS 日付型でEXCEL出力
-
差し込み印刷のときに...
-
Accessの「フィールドプロパテ...
おすすめ情報