我有一个将“ConversiePDF”表转换为PDF的vba代码 问题是整个工作表是由公式生成的,一半的工作表填充了数据而另一半仍然是空白的(公式正在运行但返回“”)
我的代码将整个工作表转换为第1000行,并生成32页(30位是空的 - 只是没有实际数据的表格)
我需要它忽略公式返回的空白单元“”如果从A到Q的整个行是空的或返回“”。 (如果一行中只有一两个或三个单元格为空,则不应该这样做)
请帮助..
'This is my code till now:
Dim ThisRng As Range
Dim strfile As String
Dim myfile As Variant
'Selectie Sheet pentru conversie
With ActiveWorkbook.Sheets("ConversiePDF")
Set ThisRng = .Range("A2", .Cells(.Rows.Count, "F").End(xlUp))
End With
谢谢..
答案 0 :(得分:0)
Private Sub CommandButton1_Click()
'BUTON CONVERSIE PDF - ANGAJATORI
'DESCRIPTION: CONVERSIE A UNUI SHEET IN PDF
Dim ThisRng As Range
Dim strfile As String
Dim myfile As Variant
'Selectie Sheet pentru conversie
Application.ScreenUpdating = False
ActiveWorkbook.Sheets("PDF ANG").Visible = True
'Selectie filtru pentru ce sa converteasca
ActiveWorkbook.Sheets("PDF ANG").Select
Selection.AutoFilter Field:=1, Criteria1:="<>" 'column A
Selection.AutoFilter Field:=5, Criteria1:="<>" 'column E
'Selectie raza pentru conversie
With ActiveWorkbook.Sheets("PDF ANG")
Set ThisRng = .Range("A2", .Cells(.Rows.Count, "F").End(xlUp))
End With
'Prompt for save location
strfile = "Selection" & "_" _
& Format(Now(), "yyyymmdd_hhmmss") _
& ".pdf"
strfile = ThisWorkbook.Path & "\" & strfile
myfile = Application.GetSaveAsFilename _
(InitialFileName:=strfile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and File Name to Save as PDF")
If myfile <> "False" Then 'save as PDF
ThisRng.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
myfile, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
Else
MsgBox "No File Selected. PDF will not be saved", vbOKOnly, "No File Selected"
End If
ActiveWorkbook.Sheets("PDF ANG").ShowAllData
ActiveWorkbook.Sheets("PDF ANG").Visible = False
End Sub