Consulting

Results 1 to 3 of 3

Thread: Copy and paste vba - Full numbers come out -1

  1. #1

    Copy and paste vba - Full numbers come out -1

    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
    Last edited by wayne123; 05-18-2023 at 06:50 AM.

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,874
    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.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Thanks p45cal, I change the Dim from date to string, and it now works perfectly. Appreciate your feedback. :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •