VBA- Test if Column is selected

jkeyes

Active Member
Joined
Apr 15, 2003
Messages
343
I know this is simple, I'm just having a "moment"... :oops:

In VBA, using an IF statement, I want to see if a column (B) is selected... help?

Thanks!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Need a little clarification.

What do you want to return:
If just one cell was selected in column B?
If more than column B was selected, say columns A:C?
 
Upvote 0
Hello jkeyes,
Something like this should work.
Code:
If Selection.Column = 2 And Selection.Count = Rows.Count Then
  MsgBox "Yes, the entire column B is selected."
Else
  MsgBox "Nope, you have something other than the entire column B selected."
End If

Hope it helps.
 
Upvote 0
Hi jkeyes

Is selection includes column B but may also include other ranges try:

Code:
If Not Intersect(Selection, Columns("B")) Is Nothing Then _
    If Intersect(Selection, Columns("B")).Address = Columns("B").Address Then _
        MsgBox "The entire Column B is selected"

Or,
Code:
If Not Intersect(Selection, Columns("B")) Is Nothing Then _
    If Intersect(Selection, Columns("B")).Rows.Count = Rows.Count Then _
        MsgBox "Column B selected"

Hope this helps
PGC
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,426
Members
448,961
Latest member
nzskater

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