私はVBAで作業しています。string
を受け取って処理し、cleaned を返すユーザー定義関数を作成しましたstring
。何が悪いのかわかりません。私はそれを呼び出して、文字列を処理して返すように依頼することができません。私はそれを定義または返す方法に誤りがあると考えています。
Public Function ProcessString(input_string As String) As String
' The temp string used throughout the function
Dim temp_string As String
For i = 1 To Len(input_string)
temp_string = Mid(input_string, i, 1)
If temp_string Like "[A-Z, a-z, 0-9, :, -]" Then
return_string = return_string & temp_string
End If
Next i
return_string = Mid(return_string, 1, (Len(return_string) - 1))
ProcessString = return_string & ", "
End Function
そして、私はこの機能をこのように使用します
Worksheets(data_sheet).Range("C2").Value = ProcessString(last_name)
姓は文字列変数で、通常は次のようLastname*****
になります。その後ろにあるすべての星を削除しようとしています。星なしで返しLastname
てもらいます。
Compile error: ByRef arugment type mismatch
これを実行しようとしたときに受け取りました。Office 2003 で Windows XP を使用しています。
編集: 私が持っているコードの基本的な構造を追加しました。同様のコードが約 20 行あります。必要なフィールドごとに同じことを行います。
Private Sub CommandButton2_Click()
' In my original production code I have a chain of these
' Like this Dim last_name, first_name, street, apt, city, state, zip As String
Dim last_name As String
' I get the last name from a fixed position of my file. Because I am
' processing it from another source which I copied and pasted into excel
last_name = Mid(Range("A4").Value, 20, 13)
' Insert the data into the corresponding fields in the database worksheet
Worksheets(data_sheet).Range("C2").Value = ProcessString(last_name)