+ Reply to Thread
Results 1 to 8 of 8

Macro stops working when re-opened

Hybrid View

  1. #1
    Registered User
    Join Date
    08-29-2011
    Location
    Cardiff
    MS-Off Ver
    Excel 2003
    Posts
    4

    Macro stops working when re-opened

    I have written a basic code to paste and sort data. It works fine when i write it, though if I close Excel it never works again. Can anyone see why.

    Code is designed to paste data copied from a report sorted to be used for a mail merge.

    Sub Update_Paypal()
    
    Application.ScreenUpdating = False
    
    'clear Data from Sheets
    
        Sheets("PayPal Input").Select
        Range("A1").Select
        Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
        Selection.ClearContents
        
        Sheets("SortedData").Select
        Range("A1").Select
        Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
        Selection.ClearContents
    
    'paste data to be sorted
        Sheets("PayPal Input").Select
        Range("A1").Select
        ActiveSheet.Paste
        
    'sort data
            Columns("P:P").Select
        Range("A1:AP10").Sort Key1:=Range("P1"), Order1:=xlAscending, Header:= _
            xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
    
        Range("A1").Select
        Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
        Selection.Copy
        
        Sheets("SortedData").Select
        Range("A1").Select
        ActiveSheet.Paste
        
        
        Sheets("Admin").Select
    
        
    Application.ScreenUpdating = True
    
        ActiveWorkbook.Save
    End Sub

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro stops working when re-opened

    Hello BarryDragon,

    Welcome to the Forum!
    • How is the macro run: manually or automatically?
    • If automatically then which event calls it?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    08-29-2011
    Location
    Cardiff
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Macro stops working when re-opened

    Hi, the Macro is run by a button click, I have the data copied already

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro stops working when re-opened

    Hello Barry,

    When you click the button, the macro runs then nothing happens on the sheet or does it error?

    If you have run the macro on the data then saved it then you wouldn't see anything happen when the macro is run again on the saved data.

  5. #5
    Registered User
    Join Date
    08-29-2011
    Location
    Cardiff
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Macro stops working when re-opened

    the macro produces an error on the first paste function. Seems that the data in the clipboard might be disappearing. Though I do not have a clue why, as i said it works if i make a new spreadsheet and put the code in, and I have another spreadsheet that does something similar (by pasting in data already in clipboard) and works fine.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro stops working when re-opened

    Where do those to be copied data come from ?

    Sub Update_Paypal()
      Application.ScreenUpdating = False
    
       Sheets("SortedData").usedrange.ClearContents
    
       with Sheets("PayPal Input")
         .usedrange.clearcontents
         .Paste
         .Range("A1:AP10").Sort .Range("P1")
    
         with .usedrange    
           Sheets("SortedData").cells(1).resize(rows.count,columns.count)=.value
        end with
      end with
    
      Application.ScreenUpdating = True
    End Sub
    Last edited by snb; 08-30-2011 at 07:00 AM.



  7. #7
    Registered User
    Join Date
    08-29-2011
    Location
    Cardiff
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Macro stops working when re-opened

    The data is copied from a paypal report in excel.

    When I use our code I get an error on the paste function...

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Macro stops working when re-opened

    if the workbook 'paypaldata' contains those data

    Sub Update_Paypal()
      Application.ScreenUpdating = False
    
      sn = workbooks("Paypaldata").sheets(1).usedrange
      Sheets("SortedData").usedrange.ClearContents
    
       with Sheets("PayPal Input")
         .usedrange.clearcontents
         .cells(1).resize(ubound(sn),ubound(sn,2))=sn
         .Range("A1:AP10").Sort .Range("P1")
    
         with .usedrange    
           Sheets("SortedData").cells(1).resize(.rows.count,.columns.count)=.value
        end with
      end with
    
      Application.ScreenUpdating = True
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1