0

I am getting the error Run-time error 1004: Method 'Range' of object'_Global' failed

I wanted to copy the macro from one workbook to another workbook to generate the test execute summary. Can someone from the community please explain where exactly is the issue:

    Sub GenerateReport()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+r
'
    'Code to get the Execution status
    '==============================================================
    Sheets("RH (2)").Select
    Range("M6").Select
  '  ActiveCell.FormulaR1C1 = "=COUNTIF(Call_eng-USA!K1:K100,""PASS"")"
    Range("M6") = WorksheetFunction.CountIf(Range("Call_eng-USA!K1:K800"), "PASS")
    Range("N6") = WorksheetFunction.CountIf(Range("Call_eng-USA!K1:K800"), "FAIL")
    Range("O6") = WorksheetFunction.CountIf(Range("Call_eng-USA!K1:K800"), "BLOCKED")
    Range("P6") = WorksheetFunction.CountIf(Range("Call_eng-USA!K1:K800"), "Not Tested")
    Range("Q6") = Range("Call_eng-USA!J2").Value
    Range("M7").Select
    'End of code
    '==============================================================
    'Code to get the open issues
    '==============================================================
    Range("R5").Select
    Sheets("Call_eng-USA").Select
    Range("M3:M82").Select
    Selection.Copy
    Sheets("RH (2)").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.UnMerge
    Range("R6").Select
    Range("R6:R100").Select
    'Code to sort the list
    ActiveWorkbook.Worksheets("RH (2)").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("RH (2)").Sort.SortFields.Add2 Key:=Range("R5:R86") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("RH (2)").Sort
        .SetRange Range("R5:S100")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Rows("5:100").EntireRow.AutoFit
    Range("R5").Select
    'Code to clear the selection
    Range("R5").Select
    Selection.End(xlDown).Select
    Range("R10:R100").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    Selection.Borders(xlEdgeBottom).LineStyle = xlNone
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    ActiveWindow.SmallScroll Down:=-53
    Range("R5").Select
    'End of code
    '====================================================================================
End Sub
  • 3
    In which line do you get the error? Have you debugged the code ans checkt what went wrong? – Shrotter Oct 13 '22 at 10:18
  • 1
    Does this answer your question? [Run-time error '1004' : Method 'Range' of object'\_Global' failed](https://stackoverflow.com/questions/12174723/run-time-error-1004-method-range-of-object-global-failed) – Tom Brunberg Oct 13 '22 at 10:30

0 Answers0