2016-07-12 7 views
0

これまでに6つの分割セル(コロン記号を使用)を同じ列に管理しています。上記の追加データがある場合はいつでも標準化しようとしています(つまり、最後の行が50の場合、最初の行は44です)。 (失敗したけど)VBA:最後の6行の ":"の後にセルを分割します。

 Dim fullstring As String, colonposition As Integer, j As Integer 
     For i=1 to 6 
     fullstring = Cells(j, 1).Value 
     colonposition = InStr(fullstring, ":") 
     Cells(j, 2).Value = Mid(fullstring, colonposition + 2) 
     Cells(j, 1).Value = Left(fullstring, colonposition - 1) 
     Next j 
私もこれを試してみました

VBAは、最後の行1行を選択するために続行する方法のよう

  Dim fullstring As String, colonposition As Integer, j As Integer, LastRow as Long, FirstRow as Long 
      LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row 
      FirstRow = LastRow - 6 
      For j = FirstRow To EndRow 
      fullstring = Cells(j, 1).Value 
      colonposition = InStr(fullstring, ":") 
      Cells(j, 2).Value = Mid(fullstring, colonposition + 2) 
      Cells(j, 1).Value = Left(fullstring, colonposition - 1) 
      Next 

どんな提案を次のように

私のコードです=最後の行 - 6?

答えて

1
Sub test() 

    Dim rng   As Range 
    Dim rngCell  As Range 
    Dim lCtr  As Long 
    Dim vArr 

    Set rng = Sheet1.UsedRange.Columns(1) 

    '/ UnComment the comments if you have to set Row limits e.g 6 from last. 
    '/ Otherwise this code will work on any range. 
' 
' If rng.Rows.Count > 7 Then 
'  Set rng = rng.Offset(rng.Rows.Count - 7).Resize(7) 

     For Each rngCell In rng.Cells 
      vArr = Split(rngCell.Value2, ":") 

      For lCtr = LBound(vArr) To UBound(vArr) 
       rngCell.Offset(0, lCtr) = vArr(lCtr) 
      Next 
     Next 
' End If 

End Sub 
+0

これは頼むことがたくさんあってもよいが、どのようにあなたがに行くか:行の(以前のように)各セルを分割、最後の行を見つけ、その下の最後の行の前半と後半を返します行? – pdx

+0

http://stackoverflow.com/questions/38349177/vba-split-cells-and-display-results-below – pdx

+0

あなたは答えとしてこれを受け入れておらず、コメントに追加の質問をしました。どのようにあなたを感心?ちょうどキッド。 :)私は私のマシンに着くときにそれを調べます。 – cyboashu

関連する問題