如何在单元格中定位文本数据并使用VBA存储它们的位置
我使用循环语句在B列的单元格中查找文本测量值,并存储其单元格位置。从这个单元格位置,我想继续沿着B列查找包含文本4Wire的每个单元格,同时读取同一行但为I列的单元格内容,并将其写入master.csv文件。在B列中找到包含文本First Article Verification的单元格后,我想停止解析文件。我的两个Do/While循环没有执行,因为我不知道Cellsi,B.值是否正确使用。关于这个问题有什么想法吗?提前谢谢如何在单元格中定位文本数据并使用VBA存储它们的位置,vba,excel,csv,Vba,Excel,Csv,我使用循环语句在B列的单元格中查找文本测量值,并存储其单元格位置。从这个单元格位置,我想继续沿着B列查找包含文本4Wire的每个单元格,同时读取同一行但为I列的单元格内容,并将其写入master.csv文件。在B列中找到包含文本First Article Verification的单元格后,我想停止解析文件。我的两个Do/While循环没有执行,因为我不知道Cellsi,B.值是否正确使用。关于这个问题有什么想法吗?提前谢谢 Sub ImportKeyDataFromCSVsCOPY() 'Su
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
我不认为Cellsi,B是一个有效的论点。i不能为零尝试从i+1开始,列不能为字母。例如,使用单元格1,2引用B1第2列第1行,单元格si,B-i不能像您所说的那样为0,但B将用作第2列