+ Reply to Thread
Results 1 to 9 of 9

Macro sometimes work, sometimes doesn't but works 100% of the time on another computer

  1. #1
    Registered User
    Join Date
    12-15-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    3

    Macro sometimes work, sometimes doesn't but works 100% of the time on another computer

    Hi,

    I have a problem with a macro that is making me go crazy.

    On computer #1, the macro works sometimes, partially or not at all. If it fails, it starts working then gives me a "Selection.PasteSpecial" error. If it works partially, the copied cells are not merged. It can work for 20 times on user profile "A" then I change to user profile "B" and it doesnt. I go back to user profile "A" and it doesn't work anymore. I go back to user profile "A", use a copied version of the file and it starts working. Unlog et relog. Nothing and now nothing works.

    On computer #2, it works 100% of the time without any glitch.

    I changed computer #1 regional settings to the same thing as computer #2 without any positive changes.

    Both computers use the same OS, Office version (2010) and the same file. Do I throw computer #1 through the window or is there something I'm missing.

    Here's the code for the macro.

    Sub Macro12()
    '
    ' Macro12 Macro
    '

    '
    Workbooks.Open Filename:= _
    "L:\Rapport Journalier\Lecture des niveaux de gaz extérieur\Rapport des lectures de gaz.xlsx"
    Rows("2:2").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Windows("Rapport Journalier.xlsm").Activate
    Range("W2:AE2").Select
    Selection.Copy
    Windows("Rapport des lectures de gaz.xlsx").Activate
    Range("A2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    Selection.Merge
    Selection.NumberFormat = "[$-F800]dddd, mmmm dd, yyyy"
    Windows("Rapport Journalier.xlsm").Activate
    Range("AM2:AP2").Select
    Selection.Copy
    Windows("Rapport des lectures de gaz.xlsx").Activate
    Range("J2").Select
    ActiveSheet.Paste
    Windows("Rapport Journalier.xlsm").Activate
    Range("G2:S2").Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows("Rapport des lectures de gaz.xlsx").Activate
    Range("N2").Select
    ActiveSheet.Paste
    Windows("Rapport Journalier.xlsm").Activate
    Range("G15:H15").Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows("Rapport des lectures de gaz.xlsx").Activate
    Range("AA2").Select
    ActiveSheet.Paste
    Windows("Rapport Journalier.xlsm").Activate
    Range("Q15:R15").Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows("Rapport des lectures de gaz.xlsx").Activate
    Range("AC2").Select
    ActiveSheet.Paste
    Windows("Rapport Journalier.xlsm").Activate
    Range("AB15:AC15").Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows("Rapport des lectures de gaz.xlsx").Activate
    Range("AE2").Select
    ActiveSheet.Paste
    Range("A2:AF2").Select
    Application.CutCopyMode = False
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    Range("N5:Z5").Select
    ActiveWorkbook.Save
    ActiveWindow.Close
    End Sub

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro sometimes work, sometimes doesn't but works 100% of the time on another computer

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro sometimes work, sometimes doesn't but works 100% of the time on another computer

    You can speed up excel and therefore your PC

    by running this Macro first:-

    Please Login or Register  to view this content.

    You need to undo its action for your programs to work properly
    NB we are disabling calculations, so delete that part if you macro needs excel to calculate automatically.

    Please Login or Register  to view this content.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Macro sometimes work, sometimes doesn't but works 100% of the time on another computer

    Maybe something like this:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    06-04-2013
    Location
    belgium
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro sometimes work, sometimes doesn't but works 100% of the time on another computer

    Hi,

    no idea what the problem is, it works with me. maybe upload your reports...

    I'm having the same kind of **** from my computer (see the post right under yours with HELP written in it)

  6. #6
    Registered User
    Join Date
    12-15-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    3

    Re: Macro sometimes work, sometimes doesn't but works 100% of the time on another computer

    Thanks alot TMS but I get this error with your code : error 438 "object doesn't support this property or method" at this line wbG.Range("A2").PasteSpecial Paste:=xlPasteValues

    Thanks

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Macro sometimes work, sometimes doesn't but works 100% of the time on another computer

    Oops, sorry ... couldn't test it

    Should be (and also on the next line):

    Please Login or Register  to view this content.

    Basically, I have created variables for the workbooks and the Activesheet for each workbook. So it should be wsG rather than wbG.

    Regards, TMS

  8. #8
    Registered User
    Join Date
    12-15-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    3

    Re: Macro sometimes work, sometimes doesn't but works 100% of the time on another computer

    After a few minor modification, it seems to work. Thanks alot

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Macro sometimes work, sometimes doesn't but works 100% of the time on another computer

    You're welcome.


    it seems to work
    My code, albeit with some tweaks? All users? All machines?

    Regards, TMS



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VBA doesn't work on different users of the same computer
    By cobermayer in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-03-2013, 11:26 AM
  2. Replies: 2
    Last Post: 11-08-2012, 05:10 PM
  3. Macro that works on PC doesn't work on Mac.
    By elrader in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-09-2012, 03:52 PM
  4. why this macro doesn't work in my boss computer!?
    By matador_24 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-22-2011, 12:35 PM
  5. Formula doesn't works on another computer!
    By mrblack in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-20-2010, 04:13 AM

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