Macro runs if ActiveCell is in column B

hmaveal

New Member
Joined
Sep 22, 2010
Messages
11
I know this is simple but can't get it to work.

I want to copy a relative range but only if the cursor is
in column B.

I will add a msgbox saying ..move the cursor to B and retry...

So I guess I use the IF..THEN..ELSE..statements

If ActiveCell = 2 (?) THEN

'''do something

ELSE

add msg box statement DIM and all that stuff

ENDIF
END SUB or something like that .. lol
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Code:
[/FONT]
[FONT=Courier New]Option Explicit[/FONT]
[FONT=Courier New]Sub selectonlyBCOL()[/FONT]
[FONT=Courier New]If Selection.Column <> 2 Then
 MsgBox "Please first select col. B to run this code...", vbCritical, "TEST"
End If
End Sub
 
Upvote 0
Code:
[/FONT]
[FONT=Courier New]Option Explicit[/FONT]
[FONT=Courier New]Sub selectonlyBCOL()[/FONT]
[FONT=Courier New]If Selection.Column <> 2 Then
 MsgBox "Please first select col. B to run this code...", vbCritical, "TEST"
End If
End Sub
I'm not exactly sure what the OP wants to do here but this doesn't actually determine if the ActiveCell is in column B (per the thread title). For example, if you select from G3 to B7 then the ActiveCell is in column G but Selection.Column = 2

So you would just need to replace 'Selection' in your code with 'ActiveCell' or may be the OP wants some code like this
Rich (BB code):
If ActiveCell.Column = 2 Then
    'Copy code goes here
Else
    MsgBox "Message"
End If
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,881
Members
452,948
Latest member
Dupuhini

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