2015-01-27 2 views
0

루프 문을 사용하여 "B"열의 셀에서 "Measured Values"텍스트를 찾고 셀 위치를 저장합니다. 이 셀 위치에서 텍스트 "4Wire"가 들어있는 각 셀을 찾고 "I"열의 셀 내용을 읽고 마스터 .csv에 씁니다. 파일. "First Article Verification"텍스트가 포함 된 열 "B"의 셀을 찾을 때 파일 구문 분석을 중지하고 싶습니다. 셀 (i, "B") 값이 올바르게 사용되는지 모르겠으므로 두 개의 Do/While 루프가 실행되지 않습니다. 문제에 대한 아이디어가 있습니까? 미리 감사드립니다.셀에서 텍스트 데이터를 찾고 VBA를 사용하여 위치를 저장하는 방법

Sub ImportKeyDataFromCSVsCOPY() 
'Summary: Import specific data from all CSV files from a folder into a single sheet 
Dim wbCSV  As Workbook 
Dim wsMstr  As Worksheet 
Dim fPath  As String 
Dim fCSV  As String 
Dim NR   As Long 
Dim fPathDone As String 
Dim Count  As Long 
Dim i   As Long 
Dim k   As Long 
Dim d   As String 
Dim MVnotFound As Boolean 
Dim Cells  As String 


fPath = "F:\i9 Tester\VB Macro spreadsheet\" 'path to CSV files, include the final \ in this string 
fPathDone = fPath & "Imported\"     'remember final \ in this string 
On Error Resume Next 
MkDir fPathDone         'creates the completed folder if missing 
On Error GoTo 0 
Set wsMstr = ThisWorkbook.Sheets("MasterCSV") 'sheet in thisworkbook to collate data into 

NR = wsMstr.Range("A" & Rows.Count).End(xlUp).Row + 1 'next empty row to add 
Count = 1 'Initialize count to 1 
Application.ScreenUpdating = False 'speed up macro 
fCSV = Dir(fPath & "*.csv")   'start the CSV file listing 
    Do While Len(fCSV) > 0 
     i = 0 
     MVnotFound = True 

     Set wbCSV = Workbooks.Open(fPath & fCSV) 'open a CSV file 
     Do While MVnotFound       'loop to find " Measured Values" text i = i + 1 
      If Cells(i, "B").Value = " Measured Value" Then 
       MVnotFound = False 
      End If 
     Loop 
     Do 
      If Cells(i, "B").Value = " 4Wire" Then 
       wsMstr.Range("H" & NR).Value = Cells(i, "I").Value 
      ElseIf Cells(i, "B").Value = " Fist Article Verification" Then 
       d = " First Article Verification" 
      End If 
      i = i + 1 
     Loop While d <> " First Article Verification" 

     wbCSV.Close False   'close the opened CSV 
     NR = NR + 1     'increment next target row 
     Name fPath & fCSV As fPathDone & fCSV   'move file to IMPORTED folder 
     fCSV = Dir     'ready next CSV filename 
    Loop 

Application.ScreenUpdating = True 
End Sub 

답변

0

셀 (i, "B")이 유효한 인수라고 생각하지 않습니다. i는 0이 될 수 없습니다 (i + 1에서 시작해보십시오). 그리고 열은 문자가 될 수 없습니다. 예를 들어 셀 (1,2)을 사용하여 B1 (열 2 행 1)을 참조하십시오.

+0

@ AAMC08, 셀 (i, "B") - "i"는 0과 같을 수는 없지만 "B"는 2 열로 일하다. – Davesexcel

관련 문제