2017-01-11 1 views
0

私のExcelシートでは以下のようなテキストの詳細がありますが、VBAコードの助けを借りて下のテキストから日付のみを抽出する必要がありました。MIDのような式も使用できませんでした日付は1桁または2桁です。私を助けてください。日付のテキストを操作する

Debit_Coverage_Report_1_2_2016_11_8_34

Debit_Coverage_Report_10_11_2015_14_19_33これを行うには

+0

このコードを実行した後、列Cでの結果を示している接頭辞オールウェイズ「Debit_Coverage_Report_」とは? –

+0

日付とその他の番号はどこですか?時/分/秒? Debit_Coverage_Report_dd_mm_yyyy_hh_mm_ss? レポート1は2016年2月1日ですか? – dgorti

+0

@sagar下記の回答を試しましたか?彼らは働いたのですか?どんなフィードバック? –

答えて

0

あなたのすべての文字列のための「Debit_Coverage_Report」滞在のあなたの接頭辞を仮定し、「_1_2_2016」dd_mm_yyyyの日付の順である(01年02月 - 2016年)、(VBA溶液)以下のコードを試してみてください。

以下
Option Explicit 

Sub ExtractDate() 

Dim LastRow As Long, i As Long, ind As Long 
Dim MyArr As Variant 
Dim DateArr() As Date 

' init Date array to a lrage size on init >> will optimize it's size later in the code 
ReDim DateArr(0 To 1000) 
ind = 0 ' <-- init DateArr array index 

' modify "Sheet1" to your sheet's name 
With Sheets("Sheet1") 

    ' in my test all data is in column B, so looking for last row with value in column B 
    LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row 

    ' loop through all cells in columns B 
    For i = 2 To LastRow 
     If .Range("B" & i).Value <> "" Then ' <-- check if the cell is not empty 
      MyArr = Split(.Range("B" & i).Value, "_") ' <-- split the string to array elements 

      DateArr(ind) = DateSerial(MyArr(5), MyArr(4), MyArr(3)) ' <-- inserting the array to DateArr array 
      ' the line below is just to show you the results on column C (next to your original string) 
      .Range("C" & i).Value = DateArr(ind) 

      ind = ind + 1 
     End If 
    Next i 

    ReDim Preserve DateArr(0 To ind - 1) ' <-- resize array to number of array elements found in worksheet     
End With 

End Sub 

スクリーンショットは

enter image description here

0

最も簡単な方法は、スプレッドシート内の列 にテキストを変換する列を選択し、[データ]タブ、列にテキストを選択しに行くことです。

そこから、

あなたに別の列へのデータのそこ者から

Debit Coverage Report 1 2 2016 11 8 34 
Debit Coverage Report 10 11 2015 14 19 33 

で終わるだろう区切り文字「_」の代わりに、デフォルトのTAB(セレクトその他)を使用し、仕上げあなたの心のコンテンツ。