Ciao Andrea,
qui trovi il file. Il foglio è stato semplificato riducendo le righe fino a T14 ma potrebbero essere centinaia. Avrei bisogno che la macro, una volta schiacciato il pulsante, visualizzi l'anteprima di stampa solo delle colonne D,C, H ovviamente solo se le righe sono compilate.
In un modulo di codice standard, incolla il seguente codice:
'========>>
Option Explicit
'-------->>
Public Sub Stampa2()
Dim SH As Worksheet
Dim i As Long
Dim LRow As Long
Const sFoglio As String = "TASK"
Set SH = ThisWorkbook.Sheets(sFoglio)
With SH
LRow = LastRow(SH, .Columns("A"))
For i = 4 To LRow
If IsEmpty(.Cells(i, 1)) Then
.Rows(i).Hidden = True
End If
Next i
.Range("A:B,E:G,I:J").EntireColumn.Hidden = True
.Columns("C").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
.Columns("C").ColumnWidth = .Columns("E").ColumnWidth
.Columns("E").Copy Destination:=.Columns("C")
.Columns("E").Hidden = True
.PageSetup.PrintArea = Intersect(.Columns("A:I"), .Rows("1:" & LRow)).Address
.PrintPreview
.Columns("A:K").Hidden = False
.Columns("C").Delete
.UsedRange.Rows.Hidden = False
End With
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range, \_
Optional minRow As Long = 1)
If Rng Is Nothing Then
Set Rng = SH.Cells
End If
On Error Resume Next
LastRow = Rng.Find(What:="\*", \_
After:=Rng.Cells(1), \_
Lookat:=xlPart, \_
LookIn:=xlFormulas, \_
SearchOrder:=xlByRows, \_
SearchDirection:=xlPrevious, \_
MatchCase:=False).Row
On Error GoTo 0
If LastRow < minRow Then
LastRow = minRow
End If
End Function
'<<========
Potresti scaricare il mio file di prova Andrea2_20210803.xlsm
===
Regards,
Norman
