Set Target.Address to a Column

Salrandin

New Member
Joined
Jun 27, 2011
Messages
32
Hi All,

I am new here and from my recent lurkings have found my pathetic vision of excel to be shattered... I did not know you could do so much in it. Anyways I am looking to learn and my first question:

Is there a clean way to set target.address to a column?

Code:
If Target.Address = "$A$1" Then

I have googled some ways to set it to a defined range but I want a whole column. Any help appreciated. Thanks.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Welcome to the board...

You should also look into using Intersect...

Code:
If Not Intersect(Target, Range("A:A")) Is Nothing Then
    'Do some stuff
End if

This will "Do some stuff" only if Target Intersects with Column A


Hope that helps.
 
Upvote 0
Welcome to the board...

You should also look into using Intersect...

Code:
If Not Intersect(Target, Range("A:A")) Is Nothing Then
    'Do some stuff
End if

This will "Do some stuff" only if Target Intersects with Column A


Hope that helps.

I see... I know how to do all the other stuff I just needed help with the range. Thanks!
 
Upvote 0
Oops another question, how do I set it to the Column 1 of Worksheet 1 if this code is on another sheet? Thanks.
 
Upvote 0
That is confusing. Please post your complete code and what you expect it to do.

Code:
If Target.Column = Sheets("Open").Column(1) Then
 
    'do stuff (havnt done this piece yet but its easy)
 
end if

I like to have all my code on a separate sheet from the data and this current code is on a worksheet named "code" so I need it to see if an event occurs in Column A of sheet "Open" which will then trigger my macro. Thanks.
 
Upvote 0
Oops another question, how do I set it to the Column 1 of Worksheet 1 if this code is on another sheet? Thanks.

You don't...

You would need to repeat the code in each individual sheet's module.

Or utilize the Workbook_SheetChange event, which goes in the ThisWorkbook Module.

Then you test the name of the sheet that was changed...
Code:
If sh.Name = "Sheet1" Then
    If Not Intersect(Target, sh.Range("A:A")) Is Nothing Then
        'Do some stuff
    End If
End If
 
Upvote 0
You don't...

You would need to repeat the code in each individual sheet's module.

Or utilize the Workbook_SheetChange event, which goes in the ThisWorkbook Module.

Then you test the name of the sheet that was changed...
Code:
If sh.Name = "Sheet1" Then
    If Not Intersect(Target, sh.Range("A:A")) Is Nothing Then
        'Do some stuff
    End If
End If

What is sh? Am i suppose to declare it as sheeet1? Sorry I am not very good at this.
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

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