Procedure too large - how can I shorten my code?

nic_hartley

New Member
Joined
Jan 14, 2010
Messages
9
I have written a macro to work from an command button to update sales reports. This command button will update the master sheet, then create, rename and save etc individual files to be emailed out to the sales guys.

The code is now too long as I am still quite new to using visual basic I do not know how to write a more sophisicated code. Please see part of my code below which im sure there is a way to shorten:

Sheets("Budget").Activate
Range("BW90").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-72],RC[-66])"
Range("BW91").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-72],RC[-66])"
Range("BW92").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-72],RC[-66])"
Range("BW93").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-72],RC[-66])"
Range("BW94").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-72],RC[-66])"
Range("BW95").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-72],RC[-66])"
Range("BW96").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-72],RC[-66])"
Range("BW97").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-72],RC[-66])"
Range("BW98").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-72],RC[-66])"
Range("BW99").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-72],RC[-66])"
Range("BW100").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-72],RC[-66])"
Range("BW101").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-72],RC[-66])"
Range("BW103").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-72],RC[-66])"


This is repeated for four areas of the spreadsheet and repeated for each of the 7 sales guys - there is surely a way to loop this?

Any help would be really appreciated!

Thanks!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Welcome to the board...

Try

Sheets("Budget").Range("BW90:BW103").FormulaR1C1 = "=SUM(RC[-72],RC[-66])"


Hope that helps..
 
Upvote 0
You can replace that with

Code:
Sheets("Budget").Activate
Range("BW90:BW103").FormulaR1C1 = "=SUM(RC[-72],RC[-66])"
 
Upvote 0

Forum statistics

Threads
1,215,647
Messages
6,126,006
Members
449,280
Latest member
Miahr

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