Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Col tuo codice si creano 3 gruppi da due colonne.
Invece io dovrei avere 3 gruppi da 3 colonne di dati.
Le 3 colonne hanno larghezza diversa.
Se è un problema nn mi costerà cmq nulla farlo manualmente
Grazie.
Io sono stato con quanto avevi postato all'inizio....;-)
Questa lavora per tre colonne:
Public Sub m()
Dim lRighe As Long
Dim lRiga As Long
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim lng As Long
Dim lCol As Long
With ThisWorkbook
Set sh1 = .Worksheets("Foglio1")
Set sh2 = .Worksheets("Foglio2")
End With
lCol = 1
lRiga = 1
sh2.Cells.ClearContents
With sh1
lRighe = .Range("A1").CurrentRegion.Rows.Count
For lng = 1 To lRighe Step 56
If lng < lRighe Then
If lCol > 6 Then
lCol = 1
lRiga = sh2.Range("A" & sh2.Rows.Count).End(xlUp).Row
End If
If lRiga = 1 Then
.Range("A" & lng & ":C" & lng + 55).Copy _
Destination:=sh2.Cells(lRiga, lCol)
Else
.Range("A" & lng & ":C" & lng + 55).Copy _
Destination:=sh2.Cells(lRiga + 1, lCol)
End If
lCol = lCol + 3
End If
Next
End With
Set sh2 = Nothing
Set sh1 = Nothing
End Sub
NOTA. Puoi formattare precedentemente il foglio di arrivo? Ho modificato il codice perchè la formattazione venga mantenuta. Considera che la macro, fra un lancio e l'altro, pulisce solo il contenuto delle celle in Foglio2, mantenendo eventuali formattazioni di righe/colonne/celle.
Questa invece copia le formattazioni delle colonne del Foglio1 3 a 3 e le imposta nel Foglio2:
Public Sub m()
Dim lRighe As Long
Dim lRiga As Long
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim lng As Long
Dim lCol As Long
With ThisWorkbook
Set sh1 = .Worksheets("Foglio1")
Set sh2 = .Worksheets("Foglio2")
End With
lCol = 1
lRiga = 1
sh2.Cells.ClearContents
Application.ScreenUpdating = False
With sh1
lRighe = .Range("A1").CurrentRegion.Rows.Count
For lng = 1 To lRighe Step 56
If lng < lRighe Then
If lCol > 6 Then
lCol = 1
lRiga = sh2.Range("A" & sh2.Rows.Count).End(xlUp).Row
End If
If lRiga = 1 Then
.Range("A" & lng & ":C" & lng + 55).Copy _
Destination:=sh2.Cells(lRiga, lCol)
Else
.Range("A" & lng & ":C" & lng + 55).Copy _
Destination:=sh2.Cells(lRiga + 1, lCol)
End If
lCol = lCol + 3
End If
Next
.Range("A:C").Copy
sh2.Range("A:C").PasteSpecial Paste:=xlPasteFormats
sh2.Range("D:F").PasteSpecial Paste:=xlPasteFormats
End With
With Application
.CutCopyMode = False
.ScreenUpdating = True
End With
Set sh2 = Nothing
Set sh1 = Nothing
End Sub
Ho messo il file utilizzato per l'esempio qui: http://www.maurogsc.eu/esempiforum11/raggruppareperstampa.zip.
Grazie per l'attenzione.