2ちゃんねる ■掲示板に戻る■ 全部 1- 最新50    

■ このスレッドは過去ログ倉庫に格納されています

Excel VBA 質問スレ Part80

353 :デフォルトの名無しさん:2024/01/11(木) 21:32:22.23 ID:jLVdVVn1.net
>>351
そんなことするなら素直に
>セルごとに隣接判定をして罫線を描く/描かないの処理
を実装すればいいんじゃねえかと
Sub test()
Dim r As Range
Dim r2 As Range
Set r2 = Selection
For Each r In Selection
If Not isSelect(r, xlEdgeTop) Then r.Borders(xlEdgeTop).LineStyle = xlContinuous
If Not isSelect(r, xlEdgeBottom) Then r.Borders(xlEdgeBottom).LineStyle = xlContinuous
If Not isSelect(r, xlEdgeLeft) Then r.Borders(xlEdgeLeft).LineStyle = xlContinuous
If Not isSelect(r, xlEdgeRight) Then r.Borders(xlEdgeRight).LineStyle = xlContinuous
Next
End Sub
Function isSelect(testRange As Range, index As XlBordersIndex) As Boolean
On Error Resume Next
Dim r As Range
For Each r In Selection
Select Case index
Case xlEdgeTop
If r.Address = testRange.Offset(-1, 0).Address Then isSelect = True
Case xlEdgeBottom
If r.Address = testRange.Offset(1, 0).Address Then isSelect = True
Case xlEdgeLeft
If r.Address = testRange.Offset(0, -1).Address Then isSelect = True
Case xlEdgeRight
If r.Address = testRange.Offset(0, 1).Address Then isSelect = True
End Select
Next
End Function
こんな感じか。行数制限あるからやってるけど、1行If は推奨しないぞ

総レス数 1004
273 KB
新着レスの表示

掲示板に戻る 全部 前100 次100 最新50
read.cgi ver 2014.07.20.01.SC 2014/07/20 D ★