Shorten this code

staticbob

Well-known Member
Joined
Oct 7, 2003
Messages
1,079
how would I code this better guys ? I have 50 or so of these macro buttons . .

cheers

Application.Goto Reference:="q1cell1"
Selection.ClearContents
Application.Goto Reference:="Risk_Profile"
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

al_b_cnu

Well-known Member
Joined
Jul 18, 2003
Messages
4,526
Hi,

how about

-----------------------------------------------------
Range("q1cell1,Risk_Profile").clearcontents
-----------------------------------------------------

HTH

alan
 

SIXTH SENSE

Well-known Member
Joined
Oct 29, 2003
Messages
1,883
Hi!
how about something like this.
You just got to code all cell reference name.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> xx1()
<SPAN style="color:#00007F">Dim</SPAN> tmp()
tmp = Array("ref1", "ref2", "ref3")
<SPAN style="color:#00007F">For</SPAN> i = <SPAN style="color:#00007F">LBound</SPAN>(tmp) <SPAN style="color:#00007F">To</SPAN> <SPAN style="color:#00007F">UBound</SPAN>(tmp)
Range(tmp(i)).ClearContents
<SPAN style="color:#00007F">Next</SPAN> i
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 

staticbob

Well-known Member
Joined
Oct 7, 2003
Messages
1,079
Thanks Al,

Any reason why that code is stopping my file from opening ? If I disable Macros it opens fine, it I enbale, I see the worksheet but then xl stops responding.

The only code I have in there is in module 1, and its just the code above repeated for 30 different range names ???

Strange.
Bob
 

al_b_cnu

Well-known Member
Joined
Jul 18, 2003
Messages
4,526
Hi Bob,

Have you got a worksheet_Change event without anApplication.EnableEvents=False?

HTh

Alan
 

staticbob

Well-known Member
Joined
Oct 7, 2003
Messages
1,079
No Alan, no other events or code in there, just these 30 subs in module 1, all linked to buttons
 

al_b_cnu

Well-known Member
Joined
Jul 18, 2003
Messages
4,526
staticbob said:
No Alan, no other events or code in there, just these 30 subs in module 1, all linked to buttons

erm ... beat me then, perhaps someone else can suggest something.

Alan
 

al_b_cnu

Well-known Member
Joined
Jul 18, 2003
Messages
4,526
Hi,

For info, StaticBob emailed me the s/sheet, the problem was caused by having two macros with the same name in a code module.

Alan
 

Forum statistics

Threads
1,186,168
Messages
5,956,337
Members
438,247
Latest member
UZev

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
Top