回答編集履歴

1

コード追記

2020/08/22 07:21

投稿

hatena19
hatena19

スコア33810

test CHANGED
@@ -45,3 +45,71 @@
45
45
 
46
46
 
47
47
  ただし、Rangeの引数は最大255字までという制限があるので、それを超える時は、その前で罫線を引いて、また、次の行から始めるという処理が必要になります。
48
+
49
+
50
+
51
+
52
+
53
+ ---
54
+
55
+ 255文字制限の対処済みコードです。
56
+
57
+
58
+
59
+ ```vba
60
+
61
+ Sub Sample2()
62
+
63
+ Dim targetRng As Range
64
+
65
+ Set targetRng = ActiveSheet.Range("A5").CurrentRegion
66
+
67
+
68
+
69
+ Dim rw As Range, ubo As String
70
+
71
+ For Each rw In targetRng.Columns(1).Cells
72
+
73
+ If rw.Value <> rw.Offset(1).Value Then
74
+
75
+ Dim ad As String
76
+
77
+ ad = "," & rw.Resize(, 3).Address(False, False)
78
+
79
+ If Len(ubo) + Len(ad) <= 255 Then
80
+
81
+ ubo = ubo & ad
82
+
83
+ Else
84
+
85
+ Debug.Print ubo
86
+
87
+ Call DrowBorder(ubo)
88
+
89
+ ubo = ad
90
+
91
+ End If
92
+
93
+ End If
94
+
95
+ Next
96
+
97
+ If ubo = "" Then Exit Sub
98
+
99
+ Call DrowBorder(ubo)
100
+
101
+ End Sub
102
+
103
+
104
+
105
+ Sub DrowBorder(ubo As String)
106
+
107
+ ubo = Mid(ubo, 2) '先頭のカンマ(,)を削除
108
+
109
+ Range(ubo).Borders(xlEdgeBottom).LineStyle = xlContinuous
110
+
111
+ End Sub
112
+
113
+
114
+
115
+ ```