nick_k
07-10-2012, 05:21 AM
I have trouble explaining my macro to take all zero cells count how many i have and show me avarage in message box.
Whats wrong ?
Sub srsadas()
Dim i, count As Integer
Dim area, cell As Range
Dim sum, avg As Double
Dim color1, color2 As Integer
Dim example As Range
i = InputBox("Give the value of i")
Set area = Application.InputBox("Select range", "Range", , , , , , 8)
For Each cell In area
cell(a + 1, b + 1).Value = 2 * i
i = i + 1
Next cell
For Each cell In area
If cell Mod 7 = 0 Or cell Mod 12 = 0 Then cell = 0
Next
color1 = InputBox("colour a")
color2 = InputBox("colour b")
For Each cell In area
If cell Mod i = 0 Then cell.Interior.ColorIndex = color2
If cell Mod i <> 0 Then cell.Interior.ColorIndex = color1
Next
Set example = area.Value = 0
sum = example.Cells.count
avg = sum / area.Cells.count
MsgBox avg
End Sub
Whats wrong ?
Sub srsadas()
Dim i, count As Integer
Dim area, cell As Range
Dim sum, avg As Double
Dim color1, color2 As Integer
Dim example As Range
i = InputBox("Give the value of i")
Set area = Application.InputBox("Select range", "Range", , , , , , 8)
For Each cell In area
cell(a + 1, b + 1).Value = 2 * i
i = i + 1
Next cell
For Each cell In area
If cell Mod 7 = 0 Or cell Mod 12 = 0 Then cell = 0
Next
color1 = InputBox("colour a")
color2 = InputBox("colour b")
For Each cell In area
If cell Mod i = 0 Then cell.Interior.ColorIndex = color2
If cell Mod i <> 0 Then cell.Interior.ColorIndex = color1
Next
Set example = area.Value = 0
sum = example.Cells.count
avg = sum / area.Cells.count
MsgBox avg
End Sub