VB6根据TEXT内容索引EXCEL的问题
各位老师:有两个问题,请教一下:
(1) afc.xlsx文件有很多行内容,需要查询A列含有"CKKR"字段所在的行,并用该行内容创建一个新文件abb.xlsx
(2) afc.xlsx文件有很多行内容,需要查询A列含有Text1字段所在的行,并将查询后的指定某列内容赋值给text2
万分感谢
[此贴子已经被作者于2023-6-21 20:18编辑过]
Dim oExcel as Object, arr, i as Long, j as Long Set oExcel = CreateObject("Excel.Application") With oExcel.WorkBooks.Open("afc.xlsx") arr = .Sheets(1).UsedRange For i=1 to UBound(arr) If InStr(arr(i,1), "CKKR")>0 Then Exit For Next i .Close End With If i>UBound(arr) Then MsgBox "没找到" Exit Sub End if With oExcel.WorkBooks.Add For j=1 to UBound(arr,2) .Sheets(1).Cells(1, j) = arr(i,j) Next i .SaveAs "abb.xlsx" .Close End With oExcel.Quit
Dim oExcel as Object, arr, i as Long, j as Long Set oExcel = CreateObject("Excel.Application") With oExcel.WorkBooks.Open("afc.xlsx") arr = .Sheets(1).UsedRange For i=1 to UBound(arr) If InStr(arr(i,1), Text1.Value)>0 Then Text2.Value = arr(i,2) Exit For End If Next i .Close End With oExcel.Quit If i>UBound(arr) Then MsgBox "没找到" Exit Sub End if