+ Reply to Thread
Results 1 to 5 of 5

Sub with two variables???

Hybrid View

  1. #1
    Rayo K
    Guest

    Sub with two variables???

    I just added a variable to a sub in a module. It used to receive an integer.
    Now it receives an integer and a string.

    Excel won't let me pass the string to it. I don't know what is going on.
    Here is my sub first line:

    Public Sub ShiftNewMonth(MachineType As Integer, MachineName As String)
    ....
    End Sub




    I call this sub from a worksheet like this:

    Private Sub NewMonthButton_Click()
    Dim shtName As String
    shtName = "Corrugator"
    ShiftNewMonth (1 , shtName)
    End Sub

    Excel wants me to put an equal sign at the end of "ShiftNewMonth (1 ,
    shtName)" as if it's a Function.

    If I remove the string and say: ShiftNewMonth (1), it lets it go, but then
    it doesn't work because the module is expecting a string. ?????

  2. #2
    Trevor Shuttleworth
    Guest

    Re: Sub with two variables???

    Try without the brackets:

    Private Sub NewMonthButton_Click()
    Dim shtName As String
    shtName = "Corrugator"
    ShiftNewMonth 1, shtName
    End Sub

    Regards

    Trevor


    "Rayo K" <RayoK@discussions.microsoft.com> wrote in message
    news:87FEAA29-4561-484A-8CFE-882AB9E939F0@microsoft.com...
    >I just added a variable to a sub in a module. It used to receive an
    >integer.
    > Now it receives an integer and a string.
    >
    > Excel won't let me pass the string to it. I don't know what is going on.
    > Here is my sub first line:
    >
    > Public Sub ShiftNewMonth(MachineType As Integer, MachineName As String)
    > ...
    > End Sub
    >
    >
    >
    >
    > I call this sub from a worksheet like this:
    >
    > Private Sub NewMonthButton_Click()
    > Dim shtName As String
    > shtName = "Corrugator"
    > ShiftNewMonth (1 , shtName)
    > End Sub
    >
    > Excel wants me to put an equal sign at the end of "ShiftNewMonth (1 ,
    > shtName)" as if it's a Function.
    >
    > If I remove the string and say: ShiftNewMonth (1), it lets it go, but then
    > it doesn't work because the module is expecting a string. ?????




  3. #3
    Rayo K
    Guest

    Re: Sub with two variables???

    Weird. Am I crazy or does VB .NET not work that way? I seem to remember
    always using parentheses.

    Oh, and thanks.It works now

    "Trevor Shuttleworth" wrote:

    > Try without the brackets:
    >
    > Private Sub NewMonthButton_Click()
    > Dim shtName As String
    > shtName = "Corrugator"
    > ShiftNewMonth 1, shtName
    > End Sub
    >
    > Regards
    >
    > Trevor
    >
    >
    > "Rayo K" <RayoK@discussions.microsoft.com> wrote in message
    > news:87FEAA29-4561-484A-8CFE-882AB9E939F0@microsoft.com...
    > >I just added a variable to a sub in a module. It used to receive an
    > >integer.
    > > Now it receives an integer and a string.
    > >
    > > Excel won't let me pass the string to it. I don't know what is going on.
    > > Here is my sub first line:
    > >
    > > Public Sub ShiftNewMonth(MachineType As Integer, MachineName As String)
    > > ...
    > > End Sub
    > >
    > >
    > >
    > >
    > > I call this sub from a worksheet like this:
    > >
    > > Private Sub NewMonthButton_Click()
    > > Dim shtName As String
    > > shtName = "Corrugator"
    > > ShiftNewMonth (1 , shtName)
    > > End Sub
    > >
    > > Excel wants me to put an equal sign at the end of "ShiftNewMonth (1 ,
    > > shtName)" as if it's a Function.
    > >
    > > If I remove the string and say: ShiftNewMonth (1), it lets it go, but then
    > > it doesn't work because the module is expecting a string. ?????

    >
    >
    >


  4. #4
    Trevor Shuttleworth
    Guest

    Re: Sub with two variables???

    If you want to return a value from your function/sub, you would use
    brackets. For example:

    sString = ShiftNewMonth (1, shtName)

    Regards

    Trevor


    "Rayo K" <RayoK@discussions.microsoft.com> wrote in message
    news:F1B2AEF4-ACAD-4051-8286-98B44058FF82@microsoft.com...
    > Weird. Am I crazy or does VB .NET not work that way? I seem to remember
    > always using parentheses.
    >
    > Oh, and thanks.It works now
    >
    > "Trevor Shuttleworth" wrote:
    >
    >> Try without the brackets:
    >>
    >> Private Sub NewMonthButton_Click()
    >> Dim shtName As String
    >> shtName = "Corrugator"
    >> ShiftNewMonth 1, shtName
    >> End Sub
    >>
    >> Regards
    >>
    >> Trevor
    >>
    >>
    >> "Rayo K" <RayoK@discussions.microsoft.com> wrote in message
    >> news:87FEAA29-4561-484A-8CFE-882AB9E939F0@microsoft.com...
    >> >I just added a variable to a sub in a module. It used to receive an
    >> >integer.
    >> > Now it receives an integer and a string.
    >> >
    >> > Excel won't let me pass the string to it. I don't know what is going
    >> > on.
    >> > Here is my sub first line:
    >> >
    >> > Public Sub ShiftNewMonth(MachineType As Integer, MachineName As String)
    >> > ...
    >> > End Sub
    >> >
    >> >
    >> >
    >> >
    >> > I call this sub from a worksheet like this:
    >> >
    >> > Private Sub NewMonthButton_Click()
    >> > Dim shtName As String
    >> > shtName = "Corrugator"
    >> > ShiftNewMonth (1 , shtName)
    >> > End Sub
    >> >
    >> > Excel wants me to put an equal sign at the end of "ShiftNewMonth (1 ,
    >> > shtName)" as if it's a Function.
    >> >
    >> > If I remove the string and say: ShiftNewMonth (1), it lets it go, but
    >> > then
    >> > it doesn't work because the module is expecting a string. ?????

    >>
    >>
    >>




  5. #5
    Andy Pope
    Guest

    Re: Sub with two variables???

    Hi,

    Either use

    Call ShiftNewMonth(1 , shtName)

    or

    ShiftNewMonth 1 , shtName

    Cheers
    Andy

    Rayo K wrote:
    > I just added a variable to a sub in a module. It used to receive an integer.
    > Now it receives an integer and a string.
    >
    > Excel won't let me pass the string to it. I don't know what is going on.
    > Here is my sub first line:
    >
    > Public Sub ShiftNewMonth(MachineType As Integer, MachineName As String)
    > ...
    > End Sub
    >
    >
    >
    >
    > I call this sub from a worksheet like this:
    >
    > Private Sub NewMonthButton_Click()
    > Dim shtName As String
    > shtName = "Corrugator"
    > ShiftNewMonth (1 , shtName)
    > End Sub
    >
    > Excel wants me to put an equal sign at the end of "ShiftNewMonth (1 ,
    > shtName)" as if it's a Function.
    >
    > If I remove the string and say: ShiftNewMonth (1), it lets it go, but then
    > it doesn't work because the module is expecting a string. ?????


    --

    Andy Pope, Microsoft MVP - Excel
    http://www.andypope.info

+ 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