Consulting

Results 1 to 6 of 6

Thread: Dynamically locate and copy last number in a column before #N/A error

  1. #1

    Dynamically locate and copy last number in a column before #N/A error

    Hi Experts,
    Please I need help with VBA code to dynamically locate and copy the last values in column E before the errors and corresponding date in column A.

    This is the amount highlighted in yellow i.e. cell E16 and in column A also highlighted in yellow i.e. cell A16 from tab "Q1" into tab "Summary". The values should be copied to cells C3 and C9 in the Summary tab of the same file.
    In this instance the cell is E16 and A16 but this varies from customer to customer.
    Below is a picture of tab Q1

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,053
    Location
    Welcome to the forum Tactful. A sample workbook is so much easier to understand rather than an image. Could you please supply a sample workbook with Q1 and Summary sheets?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Contributor Daxton A.'s Avatar
    Joined
    Jun 2004
    Location
    Biloxi, Mississippi
    Posts
    143
    Location
    Try using the code:

    =If(or(E2= "",f2=""),"",E2-B2)
    Last edited by Aussiebear; 04-23-2023 at 04:16 PM. Reason: Added code tags
    “All right now ya wise guy … Dance!”

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,053
    Location
    Maybe try this
    Sub copyvalues ()
      Dim f As Range
      Dim i As Long
      
      With Sheets("Q1")
        Set f = .Range("E:E").Find("#N/A", , xlValues, xlWhole, , , False)
        If Not f Is Nothing Then
          i = f.Row - 1
          .Range("A" & i & ","E" & i).Copy 
          Sheets("Summary").Range("C3" & “C9” ).Paste
        End If
      End With
    End Sub
    Mind you, most of this code will look very familiar to you Tactful? I mean after all its from MrExcel where you were receiving help, that you failed to mention.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,189
    Location
    See attached and below for some Excel 365 options if you have 365?

    Get whole row:
    PHP Code:
    =LET(data,A2:F25,i,MIN(IFERROR(BYCOL(data,LAMBDA(x,MATCH(TRUE,ISNA(x),0))),""))-1,DROP(TAKE(data,i),i-1)) 
    Get only column E value:
    PHP Code:
    =INDEX(LET(data,A2:F25,i,MIN(IFERROR(BYCOL(data,LAMBDA(x,MATCH(TRUE,ISNA(x),0))),""))-1,DROP(TAKE(data,i),i-1)),,5
    OR:
    PHP Code:
    =LET(f,FILTER(E2:E25,NOT(ISNA(E2:E25))),DROP(f,ROWS(f)-1)) 
    Attached Files Attached Files
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2403, Build 17425.20146

  6. #6
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,189
    Location
    Quote Originally Posted by Aussiebear View Post
    Mind you, most of this code will look very familiar to you Tactful? I mean after all its from MrExcel where you were receiving help, that you failed to mention.
    @Aussiebear:
    I was aware of your post above but i am still playing with the Excel 365 functions...
    Last edited by georgiboy; 03-22-2023 at 08:29 AM.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2403, Build 17425.20146

Posting Permissions

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