Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
If Not Intersect(Target, Range("c8:c20", "j8:j20")) Is Nothing Then
CheckBox1.Top = Target.Top + Target.Height / 3
CheckBox1.Left = Target.Left + Target.Width / 3
With Sheets("Foglio2").Range("B:B")
Set rng = .Find(What:=Target.Offset(0, 3).Value, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
CheckBox1.Value = True
Else
CheckBox1.Value = False
End If
End With
End If
End Sub
Private Sub CheckBox1_Click()
Dim ur As Integer
Dim ro As Integer
Dim col As Integer
Dim rng As Range
ur = Sheets("Foglio2").Cells(Rows.Count, 1).End(xlUp).Row
ro = Worksheets("Foglio1").Shapes("CheckBox1").TopLeftCell.Row
col = Worksheets("Foglio1").Shapes("CheckBox1").TopLeftCell.Column
If CheckBox1.Value = True Then
Sheets("Foglio2").Cells(ur + 1, 1).Value = Sheets("Foglio1").Cells(ro, col).Offset(0, 2).Value
Sheets("Foglio2").Cells(ur + 1, 2).Value = Sheets("Foglio1").Cells(ro, col).Offset(0, 3).Value
Sheets("Foglio2").Cells(ur + 1, 3).Value = Sheets("Foglio1").Cells(ro, col).Offset(0, 4).Value
Else
With Sheets("Foglio2").Range("B:B")
Set rng = .Find(What:=Cells(ro, col).Offset(0, 3).Value, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
rng.EntireRow.Delete
End If
End With
End If
End Sub
|