0
Sub RoasPercentageGenerator()

    Dim lastrow As Long
    lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
        
    For i = 3 To lastrow
        If Sheet1.Cells(i, 2) > 50 And Not IsEmpty(Sheet1.Cells(i, 184)) Then
            Sheet2.Cells(i, 1) = Sheet1.Cells(i, 1)
            Sheet2.Cells(i, 2) = Application.WorksheetFunction.SumIf(Sheet1.Range(Cells(2, 3), Cells(2, 25)), "Ad Revenue", Sheet1.Range(Cells(i, 3), Cells(i, 25)))
        End If
    Next i

End Sub
Raymond Wu
  • 3,357
  • 2
  • 7
  • 20
  • I think you supposed to tell us what's wrong..? Other than missing declaration for `i`, there's no compile error. – Raymond Wu Dec 01 '21 at 10:03
  • 1
    You need to qualify the `Cells` properties with the same sheet as the enclosing `Range` property. – Rory Dec 01 '21 at 10:04
  • The error that pops up is "Method 'Range' of object '_Worksheet' failed". Would be glad if you can tell me what to do specifically since I am quite new to VBA. – Ömer Kadıoğlu Dec 01 '21 at 10:12
  • 1
    `Sheet2.Cells(i, 2) = ... Sheet1.Range(Cells(2, 3),Cells(2, 25))... Sheet1.Range(Cells(i, 3),Cells(i, 25)))` needs to be fully qualified. So something like `Sheet2.Cells(i, 2) = ... Sheet1.Range(Sheet1.Cells(2, 3),Sheet1.Cells(2, 25))... Sheet1.Range(Sheet1.Cells(i, 3),Sheet1.Cells(i, 25)))` @ÖmerKadıoğlu – Raymond Wu Dec 01 '21 at 10:26
  • @RaymondWu I thank you from the bottom of my heart – Ömer Kadıoğlu Dec 01 '21 at 11:00

0 Answers0