Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to set multiple columns in "If Target.Column ="
Sorry, forgot to chage part of the code while editing. The code should read
like this: Private Sub Worksheet_Change(ByVal Target As Range) 'if using the change event If Not Intersect(Target, Range("G:M")) Is Nothing Then _ MsgBox Target.Address End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'if using the selection change event If Not Intersect(ActiveCell, Range("G:M")) Is Nothing Then _ MsgBox ActiveCell.Address End Sub If you want your macro to affect all cells of the selection that are within the specidfied columns, you can use the range resulting from the Intersect() directly, e.g.: Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'if using the selection change event Set myRange = Intersect(Target, Range("G:M")) If Not myRange Is Nothing Then _ myRange .Interior.ColorIndex = 3 End Sub Regards, KL "KL" <lapink2000(at)hotmail.com wrote in message news:... Brad, You can use the Intersect() function Private Sub Worksheet_Change(ByVal Target As Range) 'if using the change event If Not Intersect(Target, Range("G:M")) Is Nothing Then _ MsgBox MyCell.Address End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'if using the selection change event If Not Intersect(ActiveCell, Range("G:M")) Is Nothing Then _ MsgBox MyCell.Address End Sub Regards, KL "Brad K." wrote in message ... I want to run the same code when one of several columns contain the active cell. How do I do this without repeating the code. When I used If Target.Column = 7 Or 8 Or 9 Or 10 Or 11 Or 12 Or 13 Then the code is executed when any cell in the sheet is selected not just in the above columns. I tried using an array without luck either. Also, I am not sure yet if all of the columns will be sequential or not. Thanks in advance for any assistance. Brad |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to set multiple columns in "If Target.Column =" | Excel Programming | |||
convert column with inches to 2 columns "feet" and "inches" | Excel Discussion (Misc queries) | |||
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell | Excel Discussion (Misc queries) | |||
How do I change the column heading in Excel to display "A" "B" "C | New Users to Excel | |||
Make pivot table with multiple "data" fields in columns not rows? | Excel Discussion (Misc queries) |