Pracuję z VBA. Napisałem funkcję definiującą użytkownika, która pobiera string
, przetwarza ją i zwraca oczyszczoną string
. Nie jestem pewien, co jest z tym nie tak. Nie jestem w stanie go wywołać i poprosić o przetworzenie ciągu znaków i zwrócenie go. Myślę, że jest błąd w sposobie definiowania lub zwracania go.Niedopasowanie argumentu ByRef w programie Excel VBA
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
I korzystać z tej funkcji jak ten
Worksheets(data_sheet).Range("C2").Value = ProcessString(last_name)
Nazwisko jest zmienną ciąg, zwykle wygląda to Lastname*****
, a ja staram się usunąć wszystkie gwiazdy za nim. Czy to powróci Lastname
bez gwiazdek.
Otrzymałem Compile error: ByRef arugment type mismatch
kiedy próbowałem to uruchomić. Używam systemu Windows XP z pakietem Office 2003.
EDYCJA: Dodałem podstawową strukturę kodu, który posiadam, mam około 20 linii podobnego kodu. Robię to samo dla każdego pola, którego potrzebuję.
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)
Na której linii znajduje się erro r flaga? – Gaffi
Spadł na linii, kiedy ja to nazywam. 'Arkusze robocze (arkusz_danych) .Range (" C2 ") Wartość = ProcessString (last_name)' – George