I am new to Excel VBA
Still I had created an macro that work as I need.
In an workbook I had two sheets(data and hello) so data's are in data sheet and print format is in hello sheet, Please find the below code which is working and the pdf is saving. But this code is only for two rows, Kindly share the code that will export more than 20 rows.
Sub prtdata()
Dim cell As Range, strPath As String
strPath = "D:\Test"
Sheets("data").Range("A3").Copy Destination:=Sheets("Hello").Range("E7")
Sheets("data").Range("B3").Copy Destination:=Sheets("Hello").Range("D9")
Sheets("data").Range("C3").Copy Destination:=Sheets("Hello").Range("D10")
Sheets("data").Range("D3").Copy Destination:=Sheets("Hello").Range("D11")
Sheets("data").Range("E3").Copy Destination:=Sheets("Hello").Range("D12")
Sheets("data").Range("F3").Copy Destination:=Sheets("Hello").Range("D13")
Sheets("data").Range("G3").Copy Destination:=Sheets("Hello").Range("D14")
Sheets("data").Range("H3").Copy Destination:=Sheets("Hello").Range("D15")
Sheets("data").Range("I3").Copy Destination:=Sheets("Hello").Range("D16")
Sheets("data").Range("J3").Copy Destination:=Sheets("Hello").Range("H9")
If Worksheets("Data").Range("A3").Value = "" Then
MsgBox "End OF the REport"
Range("A3").Select
Exit Sub
Else
Worksheets("Hello").Range("B4:I20").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPath & Worksheets("Data").Range("A3").Value & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Sheets("data").Range("A4").Copy Destination:=Sheets("Hello").Range("E7")
Sheets("data").Range("B4").Copy Destination:=Sheets("Hello").Range("D9")
Sheets("data").Range("C4").Copy Destination:=Sheets("Hello").Range("D10")
Sheets("data").Range("D4").Copy Destination:=Sheets("Hello").Range("D11")
Sheets("data").Range("E4").Copy Destination:=Sheets("Hello").Range("D12")
Sheets("data").Range("F4").Copy Destination:=Sheets("Hello").Range("D13")
Sheets("data").Range("G4").Copy Destination:=Sheets("Hello").Range("D14")
Sheets("data").Range("H4").Copy Destination:=Sheets("Hello").Range("D15")
Sheets("data").Range("I4").Copy Destination:=Sheets("Hello").Range("D16")
Sheets("data").Range("J4").Copy Destination:=Sheets("Hello").Range("H9")
If Worksheets("Data").Range("A4").Value = "" Then
MsgBox "End OF the REport"
Range("A4").Select
Exit Sub
Else
Worksheets("Hello").Range("B4:I20").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPath & Worksheets("Data").Range("A4").Value & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
End If
End Sub
Still I had created an macro that work as I need.
In an workbook I had two sheets(data and hello) so data's are in data sheet and print format is in hello sheet, Please find the below code which is working and the pdf is saving. But this code is only for two rows, Kindly share the code that will export more than 20 rows.
Sub prtdata()
Dim cell As Range, strPath As String
strPath = "D:\Test"
Sheets("data").Range("A3").Copy Destination:=Sheets("Hello").Range("E7")
Sheets("data").Range("B3").Copy Destination:=Sheets("Hello").Range("D9")
Sheets("data").Range("C3").Copy Destination:=Sheets("Hello").Range("D10")
Sheets("data").Range("D3").Copy Destination:=Sheets("Hello").Range("D11")
Sheets("data").Range("E3").Copy Destination:=Sheets("Hello").Range("D12")
Sheets("data").Range("F3").Copy Destination:=Sheets("Hello").Range("D13")
Sheets("data").Range("G3").Copy Destination:=Sheets("Hello").Range("D14")
Sheets("data").Range("H3").Copy Destination:=Sheets("Hello").Range("D15")
Sheets("data").Range("I3").Copy Destination:=Sheets("Hello").Range("D16")
Sheets("data").Range("J3").Copy Destination:=Sheets("Hello").Range("H9")
If Worksheets("Data").Range("A3").Value = "" Then
MsgBox "End OF the REport"
Range("A3").Select
Exit Sub
Else
Worksheets("Hello").Range("B4:I20").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPath & Worksheets("Data").Range("A3").Value & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Sheets("data").Range("A4").Copy Destination:=Sheets("Hello").Range("E7")
Sheets("data").Range("B4").Copy Destination:=Sheets("Hello").Range("D9")
Sheets("data").Range("C4").Copy Destination:=Sheets("Hello").Range("D10")
Sheets("data").Range("D4").Copy Destination:=Sheets("Hello").Range("D11")
Sheets("data").Range("E4").Copy Destination:=Sheets("Hello").Range("D12")
Sheets("data").Range("F4").Copy Destination:=Sheets("Hello").Range("D13")
Sheets("data").Range("G4").Copy Destination:=Sheets("Hello").Range("D14")
Sheets("data").Range("H4").Copy Destination:=Sheets("Hello").Range("D15")
Sheets("data").Range("I4").Copy Destination:=Sheets("Hello").Range("D16")
Sheets("data").Range("J4").Copy Destination:=Sheets("Hello").Range("H9")
If Worksheets("Data").Range("A4").Value = "" Then
MsgBox "End OF the REport"
Range("A4").Select
Exit Sub
Else
Worksheets("Hello").Range("B4:I20").ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=strPath & Worksheets("Data").Range("A4").Value & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
End If
End Sub