title: Calling a function in VBA
body: <p>I am trying to write a function that passes two string arguments and returns string type and I am calling the same function through a sub. I am getting an error with the arguments suggesting argument mismatch whereas I checked and the arguments are correct. Cant see to understand where the problem is. Can someone please help out . Here is the code</p>
  
  <pre><code>    Sub TableCat()
      Dim Key As String
      Worksheets("Table").Activate
      Call RemoveDupes
      Do Until ActiveCell.Value = ""
       TableMode = Application.Trim(ActiveCell.Value)
       TableId = Application.Trim(ActiveCell.Offset(0, -1).Value)
       ControlID = Application.Trim(ActiveCell.Offset(0, -2).Value)
       Key = ControlID &amp; TableId
       ActiveCell.Offset(0, 1).Value = TableCatCalling(Key, TableMode)
      ActiveCell.Offset(1, 0).Select
      Loop
      End Sub
  </code></pre>
  
  <p>The function </p>
  
  <pre><code>    Function TableCatCalling(Key As String, Mode As String) As String
      Dim CatCell As Range
      Dim searchRange As Range
      Worksheets("CCM Analysisv2").Activate
      Set searchRange = Range("C1", Range("C1").End(xlDown))
      Set CatCell = searchRange.Find(what:=Key, lookAt:=xlWhole)
      If CatCell Is Nothing Then
       TableCatCalling = " "
      Else
       If TableMode Like "New" Then
          TableCatCalling = CatCell.Offset(0, -1).Value
       End If
      End If
      Worksheets("Table").Activate
      End Function
  </code></pre>