Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click Excel cell to fill 1

Status
Not open for further replies.

tbalazs

IS-IT--Management
Dec 18, 2000
158
GB
Is it possible to fill a (any) cell with, say, red, by clicking on it? I have no idea about VBa code which could accomplish this.
Thanks,
Tony.
 
Insert the following code into the Sheet's code module where you want to have the selected cells turn red upon selecting them.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Target.Interior.ColorIndex = 3
End Sub

I hope this helps!

Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Thank you, Mike.

The code seems correctly inserted (the module is Worksheet_SelectionChange) but nothing happens when I select a cell.

Tony.
 
Check to see that you have the event procedure in the Worksheet's code module and not in a standard code module.

On the left side of the VBE, you will see a list containing all of the open Add_in and Workbook VBA Projects. Find your Workbook project and look in the folder "Microsoft Excel Objects".

In this folder you will see the sheet objects in the workbook and the workbook object. Select the sheet object that you want to give this functionality to and copy the code into it.

It will only work for that specific worksheet. If you want it to work for all of the worksheets in your workbook, you will have to copy the event procedure into each worksheets code module or create a class module that controls worksheet events.

I hope this is understandable!



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Great Mike. That was really helpful. It now works!
Thank you.
Tony.
 
Hey Tony,

just a quick tip:

If you only want to change one cell and not have to worry about the user selection more than one cell use the ActiveCell Object instead of Target

[thumbsup2]



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top