[[20200522155705]] 『網掛けの範囲を広げたい』(raider) ページの最後に飛ぶ

[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]

 

『網掛けの範囲を広げたい』(raider)

 Dim k As Integer
    Dim i As Integer

    '網掛け
    'For i = 7 To Range("A" & Rows.Count).End(xlUp).Row
    '    If Cells(i, 1).Value <> "" And Cells(i, 1).Value <> "" And Cells(i, 1).Value <> "合計" Then
    '        Cells(i, 1).Interior.Pattern = xlLightDown
    '        Cells(i, 2).Interior.Pattern = xlLightDown
    '        Cells(i, 3).Interior.Pattern = xlLightDown
    '        Cells(i, 4).Interior.Pattern = xlLightDown
    '        'xlPatternNone
    '    Else
    '    End If
    'Next i

現在表をこのような式を用いてA〜D列のうちD列の行のみ
網掛けしています。
この網掛け範囲をA〜D列の4行に広げたいのですが、どこを書き換えれば良いでしょうか。

< 使用 Excel:Excel2016、使用 OS:Windows7 >


 >この網掛け範囲をA〜D列の4行に広げたいのですが
  4列なら

 '  網掛け
    For i = 7 To Range("A" & Rows.Count).End(xlUp).Row
        If Cells(i, 1).Value <> "" And Cells(i, 1).Value <> "合計" Then
            Cells(i, 1).Resize(, 4).Interior.Pattern = xlLightDown
        Else
            Cells(i, 1).Resize(, 4).Interior.Pattern = xlPatternNone
        End If
    Next i

(ピンク) 2020/05/22(金) 16:34


ピンク様

いただいた式を使ってみたところ、網掛けしたく無い行まで網掛けしてしまうようになってしまいました。
"合計"があるのはC列で実際に網掛けされていたのはD列なのですが、D列に網掛けされたら前の3列にも網掛けをするという風にしたいのですが、可能でしょうか。

(raider) 2020/05/22(金) 16:45


 >"合計"があるのはC列で実際に網掛けされていたのはD列なのですが

 なら
 If Cells(i, 1).Value <> "" And Cells(i, 1).Value <> "合計" Then
            ↓
 If Cells(i, 1).Value <> "" And Cells(i, "C").Value <> "合計" Then

(ピンク) 2020/05/22(金) 16:55


ピンク様
やはり関係ない行まで網掛けしてしまいます。
元の式に追加する形でD列が網掛けされていたら前の3列も網掛けをする、という形にはできないでしょうか?
(raider) 2020/05/22(金) 17:02

 >D列が網掛けされていたら前の3列も網掛けをする、という形にはできないでしょうか?

   For i = 7 To Range("A" & Rows.Count).End(xlUp).Row
        If Cells(i, "D").Interior.Pattern = xlLightDown Then
            Cells(i, 1).Resize(, 3).Interior.Pattern = xlLightDown
        Else
            Cells(i, 1).Resize(, 3).Interior.Pattern = xlPatternNone
        End If
   Next i

(ピンク) 2020/05/22(金) 17:14


 >'For i = 7 To Range("A" & Rows.Count).End(xlUp).Row
 > '   If Cells(i, 1).Value <> "" And Cells(i, 1).Value <> "" And Cells(i, 1).Value <> "合計" Then

 結局、理解できなかったのですが網掛けをするのは D列に"合計"があるA〜D列

 それともD列に"合計"が無いA〜D列

(ピンク) 2020/05/22(金) 17:24


  網掛けパターンがxlLightDown 以外にも対応

   For i = 7 To Range("A" & Rows.Count).End(xlUp).Row
        If Cells(i, "D").Interior.Pattern <> xlPatternNone Then
            Cells(i, 1).Resize(, 3).Interior.Pattern = Cells(i, "D").Interior.Pattern
        Else
            Cells(i, 1).Resize(, 3).Interior.Pattern = xlPatternNone
        End If
   Next i

(ピンク) 2020/05/22(金) 17:40


コメント返信:

[ 一覧(最新更新順) ]


YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki. Modified by kazu.