2016-06-25 13 views
1

これはVBAで何もコーディングしていない初めてのことです。ファイルを読み込んでビットとピースをwestまたはcolumnのどちらかの列に分ける短いマクロを作成しようとしています。VBAでの単純なループが動作しない

すべてが間違っているかもしれませんし、単純なものかもしれませんが、現時点では私のdoループも認識しません。どんな助けも大歓迎です。

Private Sub seperateTextFile() 
    Dim file As String 
    Dim text As String 
    Dim textLine As String 

    Dim west As Boolean 
    west = True 

    file = ".alltxt" 

    Open file For Input As #1 

    Do Until EOF(1) 
     Line Input #1, textLine 
     text = textLine 
     If InStr(text, "HMW") <> 0 Then 
      west = True 
     If InStr(text, "other") <> 0 Then 
      west = False 
     If west = True Then 
      Sheets("Sheet2").Range("West").End(x1Up) = text 
     If west = False Then 
      Sheets("Sheet2").Range("East").End(x1Up) = text 
    Loop 

    Close #1 

    End Sub 
+1

として実際のパスと名前を持つために必要な必要があります'End If' –

答えて

1

if30がある場合は、elesifが不足していると思います。そして、あなたは私のためにEnd if

Dim file As String 
Dim text As String 
Dim textLine As String 

Dim west As Boolean 
west = True 

file = "c:\temp\a.alltxt" 

Open file For Input As #1 

Do Until EOF(1) 
    Line Input #1, textLine 
    text = textLine 
    If InStr(text, "HMW") <> 0 Then 
     west = True 
    ElseIf InStr(text, "other") <> 0 Then 
     west = False 
    ElseIf west = True Then 
     'Sheets("Sheet2").Range("West").End(x1Up) = text 
    ElseIf west = False Then 
     'Sheets("Sheet2").Range("East").End(x1Up) = text 
    End If 
Loop 

Close #1 

そして、あなたのfile = ".alltxt"は{テスト}が続いて{アクション} `1行にある場合は、それが必要と`ない限り、このようなfile = "c:\temp\a.alltxt"

+1

これらは排他的なものではないので、上記のコメントが見つかると、すべてを個々の行に移動する必要がありました。私が目的で削除したファイルパスですが、これを指摘してくれてありがとう。 – user3431504

関連する問題