| 
    
     |  | 動かしたい画像を"thing1" C5のセルにオートシェイプで作った透明の四角を置き"thing2"
 別のセルにオートシェイプで作った透明の四角を置き"thing3"として、
 "thing1"と"thing2"が重なったら"thing1"を"thing2"の場所に移動、
 重ならなかったら"thing3"の場所に戻すようにしました。
 
 2回目以降エラーが出ます。
 どこを直したらいいでしょうか。
 わかる方、教えてください。
 
 
 Sub check()
 
 Dim X(1 To 3) As Integer 'X座標
 Dim Y(1 To 3) As Integer 'Y座標
 Dim W(1 To 3) As Integer '幅
 Dim H(1 To 3) As Integer '高さ
 
 Dim i As Integer
 Dim kasanari As Boolean
 
 For i = 1 To 3
 
 X(i) = ActiveSheet.Shapes("thing" & i).Left
 Y(i) = ActiveSheet.Shapes("thing" & i).Top
 W(i) = ActiveSheet.Shapes("thing" & i).Width
 H(i) = ActiveSheet.Shapes("thing" & i).Height
 
 Next i
 
 If Y(1) < Y(2) + H(2) Then
 If Y(1) + H(1) > Y(2) Then
 If X(1) < X(2) + W(2) Then
 If X(1) + W(1) > X(2) Then
 kasanari = True
 End If
 End If
 End If
 End If
 
 If kasanari Then
 With ActiveSheet.Shapes("thing1")
 .Top = Y(2)
 .Left = X(2)
 End With
 Else
 With ActiveSheet.Shapes("thing1")
 .Top = Y(3)
 .Left = X(3)
 End With
 End If
 
 End Sub
 
 |  |