Buon Giorno
Ho cannibalizzato diversi codici trovati nella community per evitare che vengano stampate le righe vuote il risultato ...funziona , pero' non riesco a trovare il metodo per fare lo stesso
con quelle colonne che contengono dati ma non vorrei venissero stampate (es.: col. C e col. H non devono apparire ).
Il codice che uso e' questo , nasconde le righe vuote ,archivia in pdf e alla fine scopre le righe nascoste .
Public Sub cbArchivia_Click()
Dim cPath As String
Dim varNomeFile As Variant
Dim lng As Long
Dim rng As Range
Dim c As Range
Dim bln As Boolean
10
Application.ScreenUpdating = False
bln = False
With Worksheets("Foglio1")
For lng = 186 To 1 Step -1
bln = False
Set rng = .Range("A" & lng & ":M" & lng)
For Each c In rng
If c.Value <> "" Then
bln = True
End If
Next
If bln = False Then
.Rows(lng).EntireRow.Hidden = True
End If
Set rng = Nothing
Next
End With
Application.ScreenUpdating = True
20
cPath = BrowseFolder("Seleziona una cartella", _
"C:", msoFileDialogViewList)
If cPath = vbNullString Then
Call MsgBox(Prompt:="Hai cancellato la selezione della cartella!", _
Buttons:=vbOKOnly + vbInformation, _
Title:="Uscendo!")
Exit Sub
End If
If Right(cPath, 1) <> Application.PathSeparator Then
cPath = cPath & Application.PathSeparator
End If
varNomeFile = Application.InputBox(Prompt:="Scrivi il nome del file PDF", _
Title:="Nome dal file PDF da salvare", _
Type:=2)
If varNomeFile = False Then Exit Sub
If Len(varNomeFile & vbNullString) = 0 Then Exit Sub
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=cPath & varNomeFile, _
Quality:=xlQualityStandard, _
OpenAfterPublish:=False
30
Application.ScreenUpdating = False
bln = False
With Worksheets("Foglio1")
For lng = 186 To 1 Step -1
bln = False
Set rng = .Range("A" & lng & ":M" & lng)
For Each c In rng
If c.Value <> "" Then
bln = True
End If
Next
If bln = False Then
.Rows(lng).EntireRow.Hidden = False
End If
Set rng = Nothing
Next
End With
On Error GoTo XIT
Application.ScreenUpdating = False
XIT:
Application.ScreenUpdating = True
End Sub
'--------->>
Public Function BrowseFolder(Title As String, _
Optional InitialFolder As String = vbNullString, _
Optional InitialView As Office.MsoFileDialogView = _
msoFileDialogViewList) As String
Dim V As Variant
Dim InitFolder As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = Title
.InitialView = InitialView
If Len(InitialFolder) > 0 Then
If Dir(InitialFolder, vbDirectory) <> vbNullString Then
InitFolder = InitialFolder
If Right(InitFolder, 1) <> "" Then
InitFolder = InitFolder & ""
End If
.InitialFileName = InitFolder
End If
End If
.Show
On Error Resume Next
Err.Clear
V = .SelectedItems(1)
If Err.Number <> 0 Then
V = vbNullString
End If
End With
BrowseFolder = CStr(V)
End Function
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
'--------->>
Public Function LastCol(SH As Worksheet, _
Optional rng As Range)
If rng Is Nothing Then
Set rng = SH.Cells
End If
On Error Resume Next
LastCol = rng.Find(What:="*", _
after:=rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function
'--------->>
Public Function SheetExists(sSheetName As String, _
Optional ByVal WB As Workbook) As Boolean
On Error Resume Next
If WB Is Nothing Then
Set WB = ThisWorkbook
End If
SheetExists = CBool(Len(WB.Sheets(sSheetName).Name))
End Function
'--------->>
Public Sub FormatReport(rng As Range)
With rng
.Parent.Rows(1).RowHeight = 30
With .Rows(1)
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
With .Font
.Bold = True
End With
End With
End With
End Sub
Grazie per i suggerimenti Claudio P