
Sub Inserisci()
Dim lr As Long
Dim miorange As Range
Dim tabella As Range
Dim cel As Range
lr = Range("A" & Rows.Count).End(xlUp).Row
Set miorange = Range("G1:g2")
Set tabella = Range("a1:c" & lr)
For Each cel In miorange
lr = Range("A" & Rows.Count).End(xlUp).Row
Cells(lr + 1, 1) = cel.Value
Cells(lr + 1, 2) = Application.WorksheetFunction.VLookup(cel, tabella, 2, False)
Cells(lr + 1, 3) = Application.WorksheetFunction.VLookup(cel, tabella, 3, False)
Cells(lr + 1, 4) = Worksheets("Foglio1").Range("A" & Rows.Count).End(xlUp).Value
Cells(lr + 1, 5) = "Descrizione_Ambiente_" & Right(Worksheets("Foglio1").Range("A" & Rows.Count).End(xlUp).Value, 1)
Next cel
Range("A1").Select
ActiveWorkbook.Worksheets("Foglio2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Foglio2").Sort.SortFields.Add Key:=Range("A2:A9") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Foglio2").Sort
.SetRange Range("A1:E9")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
|
Sub inserisci()
Dim ur As Long
ur = Worksheets("Matrice").Range("F" & Rows.Count).End(xlUp).Row
ActiveCell.Copy Destination:=Worksheets("Matrice").Range("F" & ur + 1)
Worksheets("Matrice").Range("F" & ur + 1).Offset(0, -1).Value = "Significativo"
Worksheets("Matrice").Range("A2:A" & ur + 1).Merge
Worksheets("Matrice").Range("b2:b" & ur + 1).Merge
Worksheets("Matrice").Range("c2:c" & ur + 1).Merge
Worksheets("Matrice").Range("d2:d" & ur + 1).Merge
End Sub |
Sub copypastecolumndata()
Sheet11.Select
Range("B4").Value = "Rischio di 1° Livello"
Range("C4").Value = "Rischio di 2° Livello"
Range("D4").Value = "Rischio di 3° Livello"
Range("E4").Value = "Rischio di 4° Livello (Negative Example Scenario)"
Sheet5.Select
Dim Rischio1 As String
Dim Rischio2 As String
Dim Rischio3 As String
Dim Rischio4 As String
Dim lastrow As Long
lastrow = Sheet5.Cells(Rows.Count, 3).End(xlUp).Row
For i = 7 To lastrow
If Cells(i, 13) = 1 Then
Rischio1 = Sheet5.Cells(i, 3)
Rischio2 = Sheet5.Cells(i, 4)
Rischio3 = Sheet5.Cells(i, 6)
Rischio4 = Sheet5.Cells(i, 8)
Sheet11.Activate
erow = Sheet11.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
Sheet11.Cells(erow, 2) = Rischio1
Sheet11.Cells(erow, 3) = Rischio2
Sheet11.Cells(erow, 4) = Rischio3
Sheet11.Cells(erow, 5) = Rischio4
Range("B:E").Columns.AutoFit
Sheet5.Activate
End If
Next i
Sheet11.Activate
End Sub
|
Sub copypastecolumndata()
Sheet11.Select
Range("B4").Value = "Rischio di 1° Livello"
Range("C4").Value = "Rischio di 2° Livello"
Range("D4").Value = "Rischio di 3° Livello"
Range("E4").Value = "Rischio di 4° Livello (Negative Example Scenario)"
Sheet5.Select
Dim Rischio1 As String
Dim Rischio2 As String
Dim Rischio3 As String
Dim Rischio4 As String
Dim lastrow As Long
Dim CountaAmbienti As Integer
CountaAmbienti = Sheet5.Cells(7, 11)
lastrow = Sheet5.Cells(Rows.Count, 3).End(xlUp).Row
For i = 7 To lastrow
For j = 1 To CountaAmbienti
If Cells(i, 13) = 1 Then
Rischio1 = Sheet5.Cells(i, 3)
Rischio2 = Sheet5.Cells(i, 4)
Rischio3 = Sheet5.Cells(i, 6)
Rischio4 = Sheet5.Cells(i, 8)
Sheet11.Activate
erow = Sheet11.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
Sheet11.Cells(erow, 2) = Rischio1
Sheet11.Cells(erow, 3) = Rischio2
Sheet11.Cells(erow, 4) = Rischio3
Sheet11.Cells(erow, 5) = Rischio4
Range("B:E").Columns.AutoFit
Sheet5.Activate
End If
Next j
Next i
Sheet11.Activate
End Sub
|
