+ Reply to Thread
Results 1 to 2 of 2

Sub

  1. #1
    Pete
    Guest

    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. #2
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1