Not rerunning code with Command Button

Zman613

New Member
Joined
Oct 26, 2017
Messages
5
I have a command button that is averaging multiple cells (doing several averages). If one of the cells are empty than that cell doesn't get added to the average. If I were then to fill in that cell with a number and click the command button it would rerun the entire code including the other averages I'm running which would mess up the averages. How do I make the code only run the averages with cells filled out once?
The code I'm using is:
Code:
Private Sub CommandButton1_Click()
    
    Dim abcd As Worksheet
    Set abcd = Sheets("Chossid")

    Application.ScreenUpdating = False    

    abcd.Range("C7").Value = Application.WorksheetFunction.Average(abcd.Range("C7"), ActiveSheet.Range("C6"))
    abcd.Range("D7").Value = Application.WorksheetFunction.Average(abcd.Range("D7"), ActiveSheet.Range("D6"))
    abcd.Range("E7").Value = Application.WorksheetFunction.Average(abcd.Range("E7"), ActiveSheet.Range("E6"))
    abcd.Range("F7").Value = Application.WorksheetFunction.Average(abcd.Range("F7"), ActiveSheet.Range("F6"))

    Application.ScreenUpdating = True

End Sub

I don't want the code to run twice For the cells that were already averaged.
If anyone can help, I would greatly appreciate it.

Thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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