Change a cell by clicking on it using VB

Bran - Jun 11, 2009 at 05:04 PM
 venkat1926 - Jun 13, 2009 at 03:58 AM
I would like to be able to change a cell's color to blue by clicking on it with the cursor using visual basic. For instance, I have 30 cells numbered 1 to 30. I want to be able to choose #4 and have it change its color automatically, but not lose the number "4" that's in the cell. How can I accomplish this please?

1 response

suppose the data are in column A
try this macro

Sub test()
Dim j As Range, k As Integer, m As Integer
Dim x, cfind As Range, add As String
On Error Resume Next
 Columns("A:A").Interior.ColorIndex = xlNone
x = InputBox("type the number you want e.g 4")
Set j = Columns("a:a").Cells.Find(what:=x, lookat:=xlWhole)

If j Is Nothing Then
MsgBox "the value " & x & " not available "
GoTo line1
End If
add = j.Address
j.Interior.ColorIndex = 3
Set j = Cells.FindNext(j)
If j Is Nothing Then GoTo line1
If j.Address = add Then GoTo line1

j.Interior.ColorIndex = 3

End Sub