PDA

View Full Version : [SOLVED:] Copy and paste vba - Full numbers come out -1



wayne123
05-18-2023, 06:38 AM
Can someone help?

This issue is with hours = Sheet9.Range("F25"), whole number get pasted to the master sheet -1/ Example 40 will come out with 39.

I found a way around this by putting + 1 after the code. However I get the opposite problem, non-full numbers increase by 1.


Sub Records_Emp_name()
Dim employ As String
Dim month As String
Dim dateST As Currency
Dim dateED As Currency
Dim hours As Date
Dim pay As String
Dim path As String
Dim fname As String
Dim nextrec As Range
employ = Sheet9.Range("D3")
month = Sheet9.Range("D9")
dateST = Sheet9.Range("C16")
dateED = Sheet9.Range("C22")
hours = Sheet9.Range("F25")
pay = Sheet9.Range("H24")
path = "C:\Users\Documents\tests macros"
fname = employ & " - " & month
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, ignoreprintareas:=False, Filename:=path & fname
Set nextrec = Sheet5.Range("A1048576").End(xlUp).Offset(1, 0)
nextrec = employ
nextrec.Offset(0, 1) = month
nextrec.Offset(0, 2) = dateST
nextrec.Offset(0, 3) = dateED
nextrec.Offset(0, 4) = hours
nextrec.Offset(0, 5) = pay
Sheet5.Hyperlinks.Add anchor:=nextrec.Offset(0, 7), Address:=path & fname & ".pdf"
End Sub

p45cal
05-18-2023, 09:39 AM
You've Dimmed hours as Date. This might not be appropriate depending on what's in Sheet9.Range("F25")
Best if you attach a small workbook with all this in.

wayne123
05-19-2023, 12:18 AM
Thanks p45cal, I change the Dim from date to string, and it now works perfectly. Appreciate your feedback. :-)