Results 1 to 7 of 7

Trouble passing variable to another function

Threaded View

  1. #1
    Registered User
    Join Date
    04-27-2011
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    4

    Trouble passing variable to another function

    Hello Everyone,

    Currently my main function is looping through the rows in the worksheet and making changes to different columns as it iterates through all of the data. In one column I have a telephone that is in a format I want changed:

    (NPA) NXX-XXXX corrected to NPANXXXXXX
    I.E. (408) 555-1212 to 4085551212

    What I am trying to do is use another function that will chop up the telephone number and return the "corrected #" and then save the new value to the cell in the corresponding row. The problem I run into is when I compile the code I get

    "Compile Error:

    ByRef argument type mismatch"

    Below is a sample of the code I am using

    Function Prep_TestCCName()
    
    ' ******************** Detail for this Procedure ********************
    '
    Dim LastRow As Double                               ' Holds value for count of rows in WS
    
        LastRow = ActiveSheet.UsedRange.Rows.Count      ' Finds last 'row' in WS
    
        For RowNumber = 2 To LastRow                    ' Start Loop
           
            Call Prep_ReFormatCTN(CTNasNumber)            ' See Procedure for details
            Cells(RowNumber, 3).Value = CTNasNumber
      
        Next RowNumber                                  ' Move to next row in WS
    
    End Function
    
    Function Prep_ReFormatCTN(CTNasNumber As String) As Integer
    
    ' ******************** Detail for this Procedure ********************
    
        If Len(Cells(RowNumber, 3).Value < 1) Then      ' Cell is empty
            CTNasNumber = Cells(RowNumber, 3).Value
        Else                                            ' Has a telephone #, format to NPANXXXXXX
            CTNasNumber = Mid(Cells(RowNumber, 3), 2, 3) & _
                        Mid(Cells(RowNumber, 3), 7, 3) & _
                        Mid(Cells(RowNumber, 3), 11, 4)
        End If
    
    End Function
    I have tried to modify my second function and change how the variable is being handled and the problem persists.

    Function Prep_ReFormatCTN(CTNasNumber As String) As Integer
    Function Prep_ReFormatCTN(CTNasNumber As String) As Double
    Function Prep_ReFormatCTN(CTNasNumber As String) As String
    
    ' Or
    
    Function Prep_ReFormatCTN(ByVal CTNasNumber As String) As Integer
    Function Prep_ReFormatCTN(ByRef CTNasNumber As String) As Integer
    I am sure it is something simple I am missing .. any idea's would be helpful.

    Thank you everyone for your time,

    Jason S
    Last edited by Jasmith; 04-28-2011 at 10:14 AM.

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