Change a cell by clicking on it using VB

[Closed]
Report
-
 venkat1926 -
Hello,
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 reply

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")
Range("a1").Select
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
Do
Set j = Cells.FindNext(j)
If j Is Nothing Then GoTo line1
If j.Address = add Then GoTo line1

j.Interior.ColorIndex = 3
Loop


line1:
End Sub