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 PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi,

how about

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

HTH

alan
 
Upvote 0
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>
 
Upvote 0
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
 
Upvote 0
Hi Bob,

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

HTh

Alan
 
Upvote 0
No Alan, no other events or code in there, just these 30 subs in module 1, all linked to buttons
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,511
Messages
6,114,054
Members
448,543
Latest member
MartinLarkin

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