Я пытаюсь понять этот код.Следуя логике, я не понимаю границ цикла «For Next» (что далее означает «где он заканчивается») и что такое break_space_position.Надеюсь, что вы все можете помочь.
Я уже пробовал читать о циклах For Next и поиске в Google break_space_position
Sub parse_names()
Dim thename As String
Dim spaces As Integer
Do Until ActiveCell = ""
thename = ActiveCell.Value
spaces = 0
For test = 1 To Len(thename)
If Mid(thename, test, 1) = " " Then
spaces = spaces + 1
End If
Next
If spaces >= 3 Then
break_space_position = space_position(" ", thename, spaces - 1)
Else
break_space_position = space_position(" ", thename, spaces)
End If
If spaces > 0 Then
ActiveCell.Offset(0, 1) = Left(thename, break_space_position - 1)
ActiveCell.Offset(0, 2) = Mid(thename, break_space_position + 1)
Else
' this is for when the full name is just a single name with no spaces
ActiveCell.Offset(0, 1) = thename
End If
ActiveCell.Offset(1, 0).Activate
Loop
End Sub
Function space_position(what_to_look_for As String, what_to_look_in As String, space_count As Integer) As Integer
Dim loop_counter As Integer
space_position = 0
For loop_counter = 1 To space_count
space_position = InStr(loop_counter + space_position, what_to_look_in, what_to_look_for)
If space_position = 0 Then Exit For
Next
End Function
, если исходная ячейка содержит «Доктор Уильям Хилер», то после запуска этого кодатам будет клетка с «Доктором Уильямом» и клетка с «Целителем».Моя конечная цель, как только я понимаю этот блок кода, состоит в том, чтобы отредактировать его, чтобы получить результат "Уильям" "Целитель"