VB Range referencing

Skebo

New Member
Joined
Feb 27, 2002
Messages
22
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.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
On 2002-03-08 14:24, Skebo wrote:
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.
Sure,
If Target.Value = "Skebo" Then ...

Regards,
 
Upvote 0
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
 
Upvote 0
On 2002-03-08 14:34, Skebo wrote:
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
You've got the wrong argument there. You need
If Target.Value = "Skebo" Then..

:)
 
Upvote 0
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

Hope this helps,

Russell
 
Upvote 0
Oops, maybe I thanked you too soon :wink:

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.
 
Upvote 0
On 2002-03-08 14:59, Skebo wrote:
Oops, maybe I thanked you too soon /board/images/smiles/icon_wink.gif

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.
Alright, let's try

If Target.Column = Range("Skebo").Column Then...

Regards,
 
Upvote 0
If Target.Column = Range("Skebo").Column Then

Seems to work fine. Thanks for your replies Barrie and Russell.
 
Upvote 0

Forum statistics

Threads
1,214,581
Messages
6,120,368
Members
448,957
Latest member
BatCoder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top