change color event doesn't work in my macro code

jackrayan

New Member
Joined
Dec 2, 2015
Messages
5
0 down vote favorite i want to make a macro that by any change in cells run automatically, so i write below code for my sheet

<code> Private Sub Worksheet_Change(ByVal Target As Range)

Dim KeyCells As Range

Set KeyCells = Range("B1:U1")

If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then

Call changecolor

End If

End Sub</code> any change for range B1 to U1 call changecolor, and changecolor code is:

<code>Sub changecolor()

Dim sum As Integer

For i = 0 To 19

ColorVar = Cells(1, i + 2).Interior.Color

If Not ColorVar = RGB(255, 255, 255) Then

sum = sum + 1

End If

Next i

Cells(1, 1).Value = sum * 5

End Sub</code> in above code any change color for range B1 to U1 should compute a simple calculation and show result in A1
but when i test my code and i change color of some of cells i can't get any result and it seems code is not sensitive about color change of cells


how can i resole my problem? or is there any other code to get my desire?



<tbody>
</tbody>
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,216,119
Messages
6,128,946
Members
449,480
Latest member
yesitisasport

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