LoginSignup
1
2

More than 5 years have passed since last update.

連続したデータの区切りで罫線を引く

Last updated at Posted at 2017-04-28

シートで値が連続する場合に、その区切りで罫線を引くためのマクロ

ExcelVBA
Option Explicit

Sub Drawlines()
    Dim i As Integer
    Dim mc As Integer   '連続性を判定する列
    Dim bm As Variant   '一つ上のセル内容
    Dim am As Variant   'セル内容

    mc = InputBox("連続データが入力されている列を教えてください", "連続データの列")
    bm = 0
    For i = 2 To Cells(Rows.Count, mc).End(xlUp).Row + 1
        am = Cells(i, mc)
        If bm <> am Then
            Range(Cells(i, mc).Address(False, False)).EntireRow.Select
            Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
            bm = am
        End If
    Next i

    Cells(1, mc).Select

End Sub

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2