How to assign a macro button to a specific column

BettyBoop0916

New Member
Joined
May 20, 2011
Messages
16
Hi there,

I have this macro:

Private Sub CommandButton2_Click()
ActiveSheet.Unprotect
Worksheets("Data").Visible = True
Sheets("Data").Select
Sheets("Data").Range("C1:I6").Select
Selection.Copy
Sheets(Index).Select
Selection.Insert Shift:=xlDown
Worksheets("Data").Visible = False
ActiveSheet.Protect
End Sub

It is attached to a button, but I only want it to work if it falls under the first column in the worksheet.

How can I prohibt this macro from running if say they press the button while the cursor is selecting a cell in column 6?

As well, is there any way to assign this macro to a particular cell? Like putting the button in cell A1, then when that macro is inserted, starting in A6, etc.

Thanks!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Maybe this

Insert as the first code-line

Code:
If ActiveCell.Column <> 1 Then Exit Sub

HTH

M.
 
Upvote 0
Hold down the Alt key, then you can let the border of the button snap to cell borders. Is this what you mean?
 
Upvote 0
Well, that sorta helped with the pressing of ALT to snap it to the shape of the cell. But what I really mean is this:

What I want to achieve is, when I press the button in that cell, I want that cell to be selected, and then run the macro. Does that make sense?

Otherwise, if I put the macro in the cell, it doesn't recognize me selecting that cell because a button is overtop of it.

And I only want it to run if it is in column A, and and two cells up from the name "Purchases".

Thanks!
 
Last edited:
Upvote 0
Hi,

1st question: i dont know how to fix a button to a cell...

2nd question: where is Purchases? Which cell?

M.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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