![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Posts: 20
|
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then ... Is there a way to reference the range in some other way, like via its Excel name or by the value in the header row? It's a real pain to fix these macros everytime I move a column. |
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
Quote:
If Target.Value = "Skebo" Then ... Regards,
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
|
|
|
|
|
|
#3 |
|
New Member
Join Date: Feb 2002
Posts: 20
|
I had already tried that. It returns a 'Run-time error: '13' type mismatch on the line If Target.Column = "Skebo" Then
Skebo is in both the name box and row1 |
|
|
|
|
|
#4 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
Quote:
If Target.Value = "Skebo" Then..
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
|
|
|
|
|
|
#5 |
|
New Member
Join Date: Feb 2002
Posts: 20
|
Just slap me next time.
Thanks that did it |
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
Target.Value refers the value in the CELL, not a range name. If you want to refer to a named range, you can do something like this:
Code:
If Not Intersect(Target, Range("skebo")) Is Nothing Then
' Target (at least part of it) is in your skebo column
End If
Russell |
|
|
|
|
|
#7 |
|
New Member
Join Date: Feb 2002
Posts: 20
|
Oops, maybe I thanked you too soon
I have: If Target.Value = "Skebo" Then ... Instead of: If Target.Column = 1 Then ... I have: Skebo in the name box and row1 for column 1(or A) The If Then evaluates as false unless I put Skebo in column A. Target.Value = 'whatever is placed in column A' which does not = "Skebo" My old code executed the Then code everytime I changed a value in column A. |
|
|
|
|
|
#8 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
Quote:
If Target.Column = Range("Skebo").Column Then... Regards,
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
|
|
|
|
|
|
#9 |
|
New Member
Join Date: Feb 2002
Posts: 20
|
Ummmm. That may have been bad
|
|
|
|
|
|
#10 |
|
New Member
Join Date: Feb 2002
Posts: 20
|
If Target.Column = Range("Skebo").Column Then
Seems to work fine. Thanks for your replies Barrie and Russell. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|