Consulting

Results 1 to 2 of 2

Thread: VBA - Macro has to run twice for it to work.

  1. #1
    VBAX Newbie
    Joined
    Aug 2017
    Posts
    3
    Location

    VBA - Macro has to run twice for it to work.

    Goodafternoon Everyone.

    Looking for a little help please.
    I have a basic Macro that stops part way through on a "Paste" command. If I run the same marco a second time is runs through and completes the sequence.
    Sub Completed()
    
    '
    ' Archive completed record
    '
    '
    'GoTo 999
    Dim a, j, k, l, m
    Dim LastRow As Long
        Sheets("To do").Select
        Columns("A:A").Select
    'Find the Task, Select and cut
    
    
        On Error GoTo Errhandler
        a = Application.InputBox(prompt:="Enter Enquiry Number: ", Type:=1)
        
        Selection.Find(What:=a, After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
            MatchCase:=True).Activate
            
        ActiveCell.Rows("1:1").EntireRow.Select
        Selection.Cut
        
        Sheets("Completed").Select
        LastRow = GetLastLine() + 1
        Rows(LastRow).EntireRow.Select
    'The Macro Stops here. The Row is selected but the Paste does not happen. 
    
        ActiveSheet.Paste
    
    
        'Go back to ToDo Sheet
        Sheets("To do").Select
        Application.CutCopyMode = False
        Sort_BySeqNo
        Cond_format
        Boarders
        Range("A" & GetLastLine()).Select
        Exit Sub
        
    Errhandler:
        Select Case Err
        Case 91:    'Error 91 "object not defined"
            Msg = "Enq Number not found !!!"
            MsgBox Msg, vbCritical
        Range("A3").Select
        End Select
        
        End Sub
    Any suggestions please?


    Regards

    Dan

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Can you post the workbook, there is other stuff there you are not showing.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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