
Public Sub SwapRanges()
Dim R1 As Range, R2 As Range, Rtemp As Range, Area As Areas
Dim Cell
Set Area = Selection.Areas
If Area.Count = 2 Then
Set R1 = Area(1)
Set R2 = Area(2)
Else
MsgBox "Occorre aver prima selezionato i due intervalli da scambiare!"
End If
If R1.Columns.Count = R2.Columns.Count And R1.Rows.Count = R2.Rows.Count Then
Set Rtemp = Range("ZZ1000").Resize(R1.Rows.Count, R1.Columns.Count)
Rtemp.Value = R1.Value
R1.Value = R2.Value
R2.Value = Rtemp.CurrentRegion.Value
Rtemp.ClearContents
Else
MsgBox "I due intervalli devono essere uguali!"
End If
Set R1 = Nothing
Set R2 = Nothing
Set Rtemp = Nothing
End Sub |
Sub trova()
Dim ma()
ReDim ma(0)
pos1 = InputBox("Inserire il corridore 1: ")
pos2 = InputBox("Inserire il corridore 2: ")
If pos1 <> "" And pos2 <> "" Then
Set fin1 = Columns(2).Find(what:=pos1, lookat:=xlWhole)
Set fin2 = Columns(2).Find(what:=pos2, lookat:=xlWhole)
If Not fin1 Is Nothing And Not fin2 Is Nothing Then
c = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 2 To c
ma(UBound(ma)) = Cells(fin1.Row, i)
ReDim Preserve ma(UBound(ma) + 1)
Next
Range(Cells(fin1.Row, 2), Cells(fin1.Row, c)) = Range(Cells(fin2.Row, 2), Cells(fin2.Row, c)).Value
For i = 1 To UBound(ma)
Cells(fin2.Row, i + 1) = ma(i - 1)
Next
Else
MsgBox "Corridori non trovati."
End If
Else
MsgBox "Valori non validi."
End If
End Sub
|
Dim pos1, pos2, c, i As Long Dim fin1, fin2 As Range |
