VBA初学者循环问题

时间:2018-04-19 19:51:48

标签: excel vba for-loop while-loop

我的代码一直只给我Sheet1.Cells(3,1)的结果。它使用顺序i输出到正确的单元格,但始终来自(3,1)中的相同输入。如何让它循环遍历第一列(3,1),(4,1)(5,1)等的输入?

Sub CorrectName()

  Dim IndexAnswers() As String
  Dim FirstLastName As String
  Dim FirstLastNameSplit() As String

  i = 3
  While Sheet1.Cells(i, 1) <> ""

    IndexAnswers() = Split(Sheet1.Cells(i, 1), ";")
    For k = 0 To UBound(IndexAnswers)
     If IndexAnswers(k) = "" Then IndexAnswers(k) = ","
     If k > 107 And k < 132 Then
      FirstLastName = FirstLastName & IndexAnswers(k)
     End If
    Next

    FirstLastNameSplit() = Split(FirstLastName, ",")
     Sheet1.Cells(i, 4) = FirstLastNameSplit(0)
     Sheet1.Cells(i, 3) = FirstLastNameSplit(1) & FirstLastNameSplit(2)
  i = i + 1
  Wend


End Sub

0 个答案:

没有答案