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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

al_b_cnu

Well-known Member
Joined
Jul 18, 2003
Messages
4,518
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,518

ADVERTISEMENT

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,518

ADVERTISEMENT

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,518
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
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,564
Messages
5,765,129
Members
425,262
Latest member
sabry

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