#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Sub

I execute this piece of code 5 times during a Sub, can
anyone tell me how to write a procedure that can be
generic e.g

Sub MyProcedure(DailyDischargeBelt(),TotalDischargBelt
(),Col,Col1)

Then ratehr that typing all of the below in 5 times
changing the variables, the procedure would handle that
for me
Ctr = 0
For Ctr = 1 To 16
DailyDischargeBelt(Ctr) = Sheets("MinorStops").Cells
(1 + Ctr, 4).Value
TotalDischargeBelt(Ctr) = Sheets("MinorStops").Cells
(1 + Ctr, 5).Value
TotalDischargeBelt(Ctr) = TotalDischargeBelt(Ctr) +
DailyDischargeBelt(Ctr)
Sheets("MinorStops").Cells(1 + Ctr, 5).Value =
TotalDischargeBelt(Ctr)
Next Ctr

Hope that makes sense

Pete

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Sub

You would put it in a separate sub, and pass the variables as arguments. As
you dont say what are the variables, it is difficulet to guess, but
something like this

GenericRoutine DailyDischargeBel, TotalDischargeBelt


Sub GenericRoutine(var1, var2)
Ctr = 0
For Ctr = 1 To 16
var1(Ctr) = Sheets("MinorStops").Cells
(1 + Ctr, 4).Value
var2(Ctr) = Sheets("MinorStops").Cells
(1 + Ctr, 5).Value
var2(Ctr) = var1(Ctr) + var2(Ctr)
Sheets("MinorStops").Cells(1 + Ctr, 5).Value = var2(Ctr)
Next Ctr
End SUb

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Pete" wrote in message
...
I execute this piece of code 5 times during a Sub, can
anyone tell me how to write a procedure that can be
generic e.g

Sub MyProcedure(DailyDischargeBelt(),TotalDischargBelt
(),Col,Col1)

Then ratehr that typing all of the below in 5 times
changing the variables, the procedure would handle that
for me
Ctr = 0
For Ctr = 1 To 16
DailyDischargeBelt(Ctr) = Sheets("MinorStops").Cells
(1 + Ctr, 4).Value
TotalDischargeBelt(Ctr) = Sheets("MinorStops").Cells
(1 + Ctr, 5).Value
TotalDischargeBelt(Ctr) = TotalDischargeBelt(Ctr) +
DailyDischargeBelt(Ctr)
Sheets("MinorStops").Cells(1 + Ctr, 5).Value =
TotalDischargeBelt(Ctr)
Next Ctr

Hope that makes sense

Pete



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"