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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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