2016-12-02 18 views
0

こんにちは、私は自分のセルの一部をcurrentdateで更新しようとしていますので、次のようにしましたが、セルを更新できませんでした。各ループ更新セルについて

EDIT:コード全体から欠落している機能を追加します。

Sub GetField32AFromCell() 

    For Each Cell In Worksheets("MM_Creation_Success").Range("G2:G9") 

     'Get cell which is right side of the current cell in for each loop 
     Dim nextRange As Variant: nextRange = Cell.Offset(0, 1).Value 

     'split the value of the cell into string array 
     Dim splitString() As String: splitString = SplitStringByNewLine(Cell) 

     For Each sString In splitString 

      Dim newLine As String: newLine = sString 
      newLine = TryGetField32A(newLine) 

      If Not newLine = "" Then 

       Dim newDateString As String: newDateString = GetCurrentDate("yymmdd") 
       Dim new32AField As String: new32AField = Mid(newLine, 7) 

       new32AField = newDateString + new32AField 
       'Set nextRange = new32AField 
       'MsgBox (nextRange) 
      End If 
     Next 
    Next 

End Sub 


    Public Function SplitStringByNewLine(stringArray As Variant) As String() 
     SplitStringByNewLine = Split(stringArray, Chr(10)) 
    End Function 

    Public Function TryGetField32A(newLine As String) As String 
     If newLine Like ("*:32A:*") Then 
     TryGetField32A = Mid(newLine, Len("*32A::"), Len(newLine)) 
     'MsgBox ("Found Tag 32A: " + field32AVal) 
    End If 
    End Function 

    Public Function GetCurrentDate(dateFormat As String) As String 
     Dim todayDate As String: todayDate = Format(Date, dateFormat,   vbMonday, vbUseSystem) 
     GetCurrentDate = todayDate 
     'MsgBox ("Current Date in Format (" + dateFormat + "): " + todayDate) 
    End Function 
+0

ここでエラーが発生していませんか?splitString = SplitStringByNewLine(Cell)?配列に割り当てようとしています –

+0

残念ですが、他の関数を貼り付けるのを忘れました – user3167398

答えて

0

あなたはnextRangeによって表されるセルにnew32AFieldを置くためのものならば、あなたは最初nextRangeが実際にセルを表しことを確認する必要がありませんが、その値が含まれます

Dim nextRange As Range: Set nextRange = Cell.Offset(0, 1) 

をそしてあなたがする必要がありますその値を設定し、表現された範囲を変更しないでください:

nextRange.Value = new32AField 
+0

私はあなたの助けに基づいて修正することができました!どうもありがとう! – user3167398

関連する問題