VBA Split String Loop

前端 未结 2 576
北荒
北荒 2021-01-21 09:16

I am trying to split a string and create a loop for going through the cells in the column.There are a few challenges:

  1. Split works for ActiveCell on

2条回答
  •  青春惊慌失措
    2021-01-21 09:53

    Chris Nelisen outlined the reasons, I had this code written before he posted, so I'll post it anyway.

    Option Explicit
    
    Sub SplitStringLoop()
    
    Dim txt As String
    Dim i As Integer
    Dim y As Integer
    Dim FullName As Variant
    Dim LastRow As Single
    
    ReDim FullName(3)
    
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    For y = 2 To LastRow
            Cells(y, 1).Select
            txt = ActiveCell.Value
            FullName = Split(txt, "-")
            For i = 0 To UBound(FullName)
               Cells(y, i + 2).Value = FullName(i)
            Next i
    Next
    End Sub
    

提交回复
热议问题