Clairexcel
New Member
- Joined
- Mar 23, 2021
- Messages
- 31
- Office Version
- 2016
- 2010
Hello again everyone, I have been working on a code for a while now.
I have two sheetts, the first one is Takings and I want to vba code to transfer data from Takings sheet to Invoice sheet, based on customer's name.
Now given that there may be multiple rows containing the same customer name, so I would like that if I enter a customer in the input message box, the code to open as many pdfs as rows related to that customer. It was working this way unill last week then something changed...
My second problem is that it now opens me a PDF after entering customer name, but after that the code gives me an error "Error run time 2147018887 document not saved and it highlights me one of the last rows, the one I underlined...
I hereby attach my code, any help is much appreciated, thank you
I have two sheetts, the first one is Takings and I want to vba code to transfer data from Takings sheet to Invoice sheet, based on customer's name.
Now given that there may be multiple rows containing the same customer name, so I would like that if I enter a customer in the input message box, the code to open as many pdfs as rows related to that customer. It was working this way unill last week then something changed...
My second problem is that it now opens me a PDF after entering customer name, but after that the code gives me an error "Error run time 2147018887 document not saved and it highlights me one of the last rows, the one I underlined...
I hereby attach my code, any help is much appreciated, thank you
VBA Code:
Sub getDataSheet1()
Dim erow As Long
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Worksheets("Takings")
Set ws2 = Worksheets("Invoice")
erow = ws1.Cells(Rows.Count, 1).End(xlUp).Row
Dim tenantno As String
cliente = InputBox("Inserisci nome cliente")
For i = 4 To erow
If ws1.Cells(i, 1) = cliente Then
ws2.Range("F2") = ws1.Cells(i, 1)
ws2.Range("A7") = ws1.Cells(i, 4)
ws2.Range("A10") = ws1.Cells(i, 7)
ws2.Range("E12") = ws1.Cells(i, 23)
ws2.Range("E13") = ws1.Cells(i, 24)
ws2.Range("E14") = ws1.Cells(i, 25)
ws2.Range("E15") = ws1.Cells(i, 26)
ws2.Range("E16") = ws1.Cells(i, 27)
ws2.Range("E17") = ws1.Cells(i, 28)
ws2.Range("F12") = ws1.Cells(i, 30)
ws2.Range("F13") = ws1.Cells(i, 31)
ws2.Range("F14") = ws1.Cells(i, 32)
ws2.Range("F15") = ws1.Cells(i, 33)
ws2.Range("F16") = ws1.Cells(i, 34)
ws2.Range("F17") = ws1.Cells(i, 35)
ws2.Range("F24") = ws2.Range("F14")
ws2.Range("F25") = ws2.Range("F15")
ws2.Range("F26") = ws1.Cells(i, 16)
Dim Path As String, mydate As String
ws2.Range("F3") = Date
ws2.Range("F4") = ws1.Cells(i, 2)
ws2.Range("F5") = ws1.Cells(i, 3)
mydate = ws2.Range("F3")
mydate = Format(mydate, "mm_dd_yyyy")
Path = "G:\Test\"
Application.DisplayAlerts = False
ActiveWorkbook.ActiveSheet.SaveAs Filename:=Path & Range("F2") & "-" & Range("A6") & "-" & mydate & ".xlsx", FileFormat:=51
[U]ActiveWorkbook.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Path & Range("F2") & "-" & Range("A6") & "-" & mydate & ".pdf", OpenAfterPublish:=True[/U]
'ActiveWorkbook.Close SaveChanges:=False
End If
Next i
' MsgBox myfilename
Application.DisplayAlerts = True
End Sub