
Option Explicit
Sub Nomesub()
Dim wb As Workbook
Dim wsFrom As Worksheet, wsTo As Worksheet
Dim x As Long, i As Long, n As Long, J As Long
Dim y As Integer, k As Integer
Dim strR As String, strL As String
Set wb = ThisWorkbook
Set wsFrom = wb.Sheets(1)
Set wsTo = wb.Sheets(2)
wsTo.Cells.ClearContents
With wsFrom
x = .Range("A" & .Rows.Count).End(xlUp).Row
For J = 0 To 3
i = 0
k = 0
n = 0
y = wsTo.Cells(1, .Columns.Count).End(xlToLeft).Column + 1
If y = 2 And wsTo.Cells(1, y - 1) = "" Then y = 1
For i = J + 1 To x Step 4
If .Cells(i, 1) <> "" Then
k = InStr(1, .Cells(i, 1), ":", vbTextCompare)
strR = Trim(Right(.Cells(i, 1), Len(.Cells(i, 1)) - k))
strL = Left(.Cells(i, 1), k - 1)
n = wsTo.Cells(.Rows.Count, J + 1).End(xlUp).Row + 1
If n = 2 And wsTo.Cells(1, y) = "" Then n = 1
If n = 1 Then
wsTo.Cells(n, y) = strL
wsTo.Cells(n + 1, y) = strR
Else
wsTo.Cells(n, y) = strR
End If
End If
Next i
Next J
End With
Set wsFrom = Nothing
Set wsTo = Nothing
Set wb = Nothing
End Sub |
Sub copia_nomi()
Dim wsFrom As Worksheet, wsTo As Worksheet
Dim ur As Long, c As Byte
Dim nomi() As Variant, n As Variant
Application.ScreenUpdating = False
Set wsFrom = Sheets("Foglio1")
Set wsTo = Sheets("Foglio2")
ur = wsFrom.Cells(Rows.Count, 1).End(xlUp).Row
nomi = Array("pippo", "pluto", "paperino")
With wsFrom
.Rows(1).Insert Shift:=xlDown
.[a1] = "Elenco"
For Each n In nomi
.Range("a1:a" & ur).AutoFilter Field:=1, Criteria1:=n & "*"
c = c + 1
.Range("a2:a" & ur).Copy wsTo.Cells(2, c)
wsTo.Columns(c).Replace n & ": ", Replacement:="", LookAt:=xlPart
wsTo.Cells(1, c) = n
Next
.[a1].AutoFilter
End With
Application.ScreenUpdating = True
End Sub |
