HELP NEEDED- Macro to return average values from a variable range fulfilling OR condition

hamdyeleraky

New Member
Joined
Dec 31, 2015
Messages
3
Hello ,

I am in urgent need of help. I am quite new to VBA so it might be something obvious but appreciate all comments
There is a dynamic range of data in "Mastersheet" in Column "I" that i would like to get their average and return it back to another sheet "Charts" in a specific cell (B1) but i would like to only average data that fulfill one OR two string conditions (Mastersheet in Column D and E)

It return an error that i am unable to debug (only that the issue is in set s1...) and i have tried normal AverageIFS and it return average for the conditions having an AND relation not OR

Please help
Thanks!
[Sub Avg()Dim x As Integer
Dim s1, s2
Dim lrow As Long


Set s1 = Worksheets("Charts")
Set s2 = Worksheets("mastersheet")
lrow = s2.Cells(Rows.Count, "C").End(xlUp).Row


For x = 2 To lrow
If s2.Range("D" & x) = "GoGreen" Or s2.Range("E" & x) = "GoGreen" Then

s1.B8.Formula = "=Average(s2.I1:I10)"
End If
Next x


End Sub]
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Without going too far, the error is on this line
Code:
Set S1 = Worksheets("Charts")
right?

Do you have a sheet called "Charts"?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top