0

I have a problem with a VBA I recently coded and I have no idea why the error turns up. The problem is that when I am running the code, it works perfectly fine. When one of my colleagues runs the code, it's perfectly fine as well. But there are some older colleagues and when they try to run the code there's the error message mentioned above.

Do you think it appears because of their older equipment or what would you suggest? Here's the code:

    Sub Datenauswerten()

    Application.ScreenUpdating = False

    Sheets("Auswertung").Visible = True

    Sheets("Auswertung").Select
    Range("A1:D100").Select
    Selection.ClearContents
    Sheets("Pivot").Select
    Range("B6").Select
    ActiveWorkbook.RefreshAll
    Range("D7").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToLeft)).Select
    Range(Selection, Selection.End(xlToLeft)).Select
    Range(Selection, Selection.End(xlToLeft)).Select
    Selection.Copy
    Sheets("Auswertung").Select
    Range("A2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, 
    SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    Sheets("Auswertung").Range("b1").Value = "Kategorie"
    Sheets("Auswertung").Range("c1").Value = "Störung"
    Sheets("Auswertung").Range("d1").Value = "Dauer [h]"
    Cells.Select
    Cells.EntireColumn.AutoFit
    Range("D1").Select
    ActiveWorkbook.Worksheets("Auswertung").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Auswertung").Sort.SortFields.Add 
    Key:=Range("D1"), _
    SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Auswertung").Sort
    .SetRange Range("A2:D100")
    .Header = xlNo
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    Range("A5:D100").Select
   Selection.ClearContents
   Range("A:A").Select
   Selection.ClearContents
   Columns("D:D").Select
   Selection.NumberFormat = "0.00"
   Sheets("Auswertung").Range("b1").Value = "Kategorie"
   Sheets("Auswertung").Range("c1").Value = "Störung"
   Sheets("Auswertung").Range("d1").Value = "Dauer [h]"
   Sheets("Auswertung").Range("A1").Select
   Sheets("Grafik").Select
   ActiveSheet.ChartObjects("Chart 1").Activate
   ActiveChart.FullSeriesCollection(1).Values = "=Auswertung!$D$2:$D$4"
   ActiveChart.FullSeriesCollection(1).XValues = "=Auswertung!$B$2:$C$4"
   Sheets("Auswertung").Select
   Range("A50").Select

   Sheets("Auswertung").Visible = False
   Application.ScreenUpdating = True
   End Sub

Thank you very much for your help!

  • 3
    You must specify a worksheet for every `Range`, `Rows`, `Columns`, etc and stop using `.Select` to solve that issue. See [How to avoid using Select in Excel VBA](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). Also avoid `ActiveWorkbook` (the one on top) and use `ThisWorkbook` (the one the code is running at) instead. Apply this technique and if the error still occurs update the code in your question, and tell where you get the error. • You must always include in which line the error occurs. – Pᴇʜ Nov 29 '18 at 09:38
  • Thank you very much for your suggestions! I'll try that now. – Lars Walther Nov 29 '18 at 09:44

0 Answers0