+ Reply to Thread
Results 1 to 2 of 2

procedure/function calling

  1. #1
    raja
    Guest

    procedure/function calling

    hi
    i am repeatedly using some stmts in the if like

    If (StrComp(s,a) = 0 Then
    Range("a" & j).Value = Sheets("sheet2").Range("a" & z).Value
    Range("b" & j).Value = Sheets("sheet2").Range("h" & z).Value
    end if
    If (StrComp(s,b)= 0 Then
    Range("a" & j).Value = Sheets("sheet2").Range("a" & z).Value
    Range("b" & j).Value = Sheets("sheet2").Range("h" & z).Value
    end if

    here, i m often using the stmts(in red) often .
    so can somebody help me how to use the procedures for (reusablitiy)
    i want to pass the values j and z as arguments to the called procedure


  2. #2
    Norman Jones
    Guest

    Re: procedure/function calling

    Hi Raja,

    One way:

    Sub Tester04()
    Dim j As Long, z As Long
    Dim s As String, a As String, b As String

    j = 1: z = 10
    s = "TEST": a = "test": b = "TEST"

    If StrComp(s, a) = 0 Then DoIt j, z

    j = 2: z = 11
    If StrComp(s, b) = 0 Then DoIt j, z
    End Sub

    Sub DoIt(jCtr As Long, zCtr As Long)
    Range("a" & jCtr).Value = Sheets("sheet2").Range("a" & zCtr).Value
    Range("b" & jCtr).Value = Sheets("sheet2").Range("h" & zCtr).Value
    End Sub


    ---
    Regards,
    Norman



    "raja" <[email protected]> wrote in message
    news:[email protected]...
    > hi
    > i am repeatedly using some stmts in the if like
    >
    > If (StrComp(s,a) = 0 Then
    > Range("a" & j).Value = Sheets("sheet2").Range("a" & z).Value
    > Range("b" & j).Value = Sheets("sheet2").Range("h" & z).Value
    > end if
    > If (StrComp(s,b)= 0 Then
    > Range("a" & j).Value = Sheets("sheet2").Range("a" & z).Value
    > Range("b" & j).Value = Sheets("sheet2").Range("h" & z).Value
    > end if
    >
    > here, i m often using the stmts(in red) often .
    > so can somebody help me how to use the procedures for (reusablitiy)
    > i want to pass the values j and z as arguments to the called procedure
    >




+ 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