macros

blondiechick

Board Regular
Joined
Oct 13, 2006
Messages
60
I never used a macro before, I tried doing this one problem in excel but when I made the button, the worksheet kept blinking.

I am supposed to create a macro named Clear, that has the shortcut key ctrl+c that clears a macro button that covers a cell. I am supposed assign the Clear macro to the button.

How would I do this?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Smells suspiciously like homework to me... :rolleyes:

I don't quite know what you mean by blinking, unless you mean you actually saw screen updating as the code did its thing, in which case you can turn it off with Application.ScreenUpdating = False (set it back to True at the end).

As for assigning code to a button, you can draw a button from the Forms toolbar, when done, you will get a menu, one of the options is "Assign Macro", choose it and select "Clear" from the list.

As for assigning a shortcut, goto Tools-->Macro-->Macros-->Select Clear-->Options-->Add your shortcut key.

Note the negativve implications of using CTRL+C, as you'll override the native keyboard COPY function. (Get extra credit on your assignment by pointing that out to whatever nitwit professor wants you to use an assigned shortcut).

What's the code supposed to do?

Smitty
 
Upvote 0
The code is supposed to clear the data in the range B4:B7.

I am so confused. Do I first select the range B4:B7 then go create macro named Clear then type in c in the shortcut box? I am so lost. Then I have to create a macro button that will be used in cell A8, that has to be assigned to the Clear macro.
 
Upvote 0
The code to clear the range should be as simple as this.
Code:
Range("B4:B7").ClearContents
To run it from a button it depends what type of button it is.

If it's from the Forms toolbar then when you create it you should get a dialog prompting you to assign it a macro.

If it's from the Control Toolbox toolbar then if you double click it then you should be transferred to the VBA Editor where you'll see a code stub like this.
Code:
Private Sub CommandButton1_Click()

End Sub
 
Upvote 0
I am so confused. Do I first select the range B4:B7 then go create macro named Clear then type in c in the shortcut box? I am so lost. Then I have to create a macro button that will be used in cell A8, that has to be assigned to the Clear macro.

You can start simple and record a macro (Tools-->Macro-->Record New Macro-->Name it "Clear"), then select B4:B7 and hit delete. The code you get will have some select statements, so replace what you get with what Norie posted.

Then draw a button from the Forms Toolbar and follow the steps I mentioned earlier to assign the macro & shortcut key. Note that your button will not be in A8. but over it, as it's an object that actually sits above the worksheet itself.

Smitty
 
Upvote 0
Its supposed to be from the Forms toolbar.

I just don't know what steps to do first.

So okay am I supposed to select the range then go to record new marco.

From there I will name it and create a shortcut.

Then I don't know what to do after that.

Do I use relevative reference?

When do I stop the marco?

When do I make the shortcut button. Do I make it when the marco is still running, or do I stop the marco first?
 
Upvote 0
In 8 easy steps:

1) Record new macro, name it "Clear" & add shortcut key
2) Select range B4:B7
3) Hit Delete key
4) Stop recording
5) Draw button from Forms toolbar over cell A8
6) Assign macro to button from menu
7) Make Norie's code modification (for extra credit)
8) Save & turn in assignment.

Smitty
 
Upvote 0

Forum statistics

Threads
1,213,515
Messages
6,114,080
Members
448,548
Latest member
harryls

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