|
お遊びコードです。
セル範囲をドラッグで選択して試してみてください。
ドラッグの方向によってstartとgoalのセルが違ってきます。
ドラッグ開始セルのアドレス情報を使用しています。
Sub test()
Dim sel As Range
Dim tl As Range
Dim tr As Range
Dim bl As Range
Dim br As Range
Dim startcell As Range
Dim goalcell As Range
Set sel = Selection
Set tl = sel.Resize(1, 1)
Set tr = tl.Offset(, sel.Columns.Count - 1)
Set bl = tl.Offset(sel.Rows.Count - 1)
Set br = tl.Offset(sel.Rows.Count - 1, sel.Columns.Count - 1)
'MsgBox "tl:" & tl.Address & vbCrLf & "tr:" & tr.Address & vbCrLf & "bl:" & bl.Address & vbCrLf & "br:" & br.Address
Select Case ActiveCell.Address
Case tl.Address
Set startcell = tl
Set goalcell = br
Case br.Address
Set startcell = br
Set goalcell = tl
Case bl.Address
Set startcell = bl
Set goalcell = tr
Case tr.Address
Set startcell = tr
Set goalcell = bl
End Select
If startcell.Address = goalcell.Address Then
startcell.Value = "s/g"
Else
startcell.Value = "start"
goalcell.Value = "goal"
End If
Set tl = Nothing
Set tr = Nothing
Set bl = Nothing
Set br = Nothing
Set startcell = Nothing
Set goalcell = Nothing
Set sel = Nothing
End Sub
|
|