Ti avevo detto che la macro proposta nell’ultimo post limita a max 51 elementi la scrittura in colonna H, ma tutti gli altri (fossero anche 1000) sarebbero stati scritti in colonna K.
Questa versione e’ una evoluzione di quella macro, e limita a 51 il numero max di elementi scritti in ogni nuova colonna; ovviamente richiede che le colonne a destra della H siano libere da altri dati, altrimenti saranno sovrascritte senza preavviso.
Il codice:
- Codice: Seleziona tutto
Sub MissingDays_V2()
Dim wArr, oArr() As Long, I As Long, rDate As Range
'----------------------
' MARZO 2026 pc-facile
' serve a creare l elenco di giorni senza schedina
' https://www.pc-facile.com/forum/viewtopic.php?f=26&t=113738&sid=37dbfe35d06937272bb7ad6f90dc5fac
'
'-------------
'
Sheets("5_tabelle").Select
'
'Leggi dati:
Set rDate = Range(Sheets("4_archivio").Range("F14"), Sheets("4_archivio").Range("F14").End(xlDown))
ReDim oArr(Application.WorksheetFunction.Min(rDate) To Application.WorksheetFunction.Max(rDate), 1 To 1)
'
'marca le date presenti:
wArr = rDate.Value
For I = 1 To UBound(wArr)
oArr((wArr(I, 1)), 1) = 1
Next I
'
'NEW:
Dim rNext As Long, kCol As Long, hMax As Long, kMax As Long, rAll As Range
Dim tDays As Long, mDays As Long, lMonth As Long
'
'Rimuovi vecchi dati, bordi e intestazioni:
Range("L65").Value = "."
Range(Range("H66"), Cells(65, Columns.Count).End(xlToLeft).Offset(51, 0)).Clear
Range(Range("H66"), Cells(65, Columns.Count).End(xlToLeft).Offset(51, 2)).Borders.LineStyle = xlNone
Range(Range("K65"), Cells(65, Columns.Count).End(xlToLeft)).Clear
'Calcola giorni interessati:
tDays = Application.WorksheetFunction.Sum(oArr)
mDays = UBound(oArr) - LBound(oArr) - tDays + 1
'calcola le aree interessate
If mDays < 52 Then
Set rAll = Range("H66").Resize(hMax, 2)
Else
Set rAll = Range("H66").Resize(51, 2)
Do
kCol = kCol + 1
mDays = mDays - 51
If mDays < 52 Then
Set rAll = Application.Union(rAll, Range("H66").Offset(0, kCol * 3).Resize(mDays, 2))
Exit Do
Else
Set rAll = Application.Union(rAll, Range("H66").Offset(0, kCol * 3).Resize(51, 2))
End If
Loop
End If
'
'mette formati e bordi standard
With rAll
'Formato celle
.NumberFormat = "ddd / dd-mmm 'yy"
.HorizontalAlignment = xlHAlignCenterAcrossSelection
'Cornice:
.BorderAround LineStyle:=xlContinuous, Weight:=xlMedium, Color:=0
'Interlinea:
With .Borders(xlInsideHorizontal)
.LineStyle = xlDash
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
End With
'
'Mette le date mancanti e i separatori di mese
kCol = 0
For I = LBound(oArr) To UBound(oArr)
If oArr(I, 1) = 0 Then
If rNext >= 116 Then
kCol = kCol + 1
Range("H65:I65").Copy Cells(65, 8 + kCol * 3)
' hMax = rNext
End If
rNext = Cells(Rows.Count, 8 + kCol * 3).End(xlUp).Row + 1
Cells(rNext, 8 + kCol * 3).Value = CDate(I)
Cells(rNext, 8 + kCol * 3).NumberFormat = "ddd / dd-mmm 'yy"
Cells(rNext, 8 + kCol * 3 + 1).NumberFormat = "General"
If rNext > 66 Then
'Mette eventuale separatore dei mesi:
If Month(I) <> lMonth Then
With Cells(rNext - 1, 8 + kCol * 3).Resize(1, 2).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = 0 ' colore della riga
.TintAndShade = 0
.Weight = xlThick ' spessore riga
End With
End If
End If
lMonth = Month(I)
End If
Next I
Range("D1").Select
End Sub
Prova, se ti interessa la prestazione