![](/img/trans.png)
[英]Find last row > merge cells > copy and paste into it - Excel VBA macros
[英]Find text in File, Copy and Paste in Cells Excel VBA
我正在VBA中編寫代碼,以在文件中查找unser在宏中輸入的字符,在宏找到用戶提供的字符后,我希望它提取整行並將其粘貼到excel中的表格中取第一個字符並將其放在單元格1a中,然后取下一組由文本中的空格分隔的字符,然后將其放入另一個單元格中,這是我到目前為止所要的,我想將第17行替換為數據;
Dim oFSO As Object
Dim arrData() As String
Sub test()
Dim f As Integer
Dim IngLine As Long
Dim strLine As String
Dim bInFound As Boolean
f = FreeFile
Tfile = "C:\TAXETI.TXT"
staffdat = InputBox(Prompt:=" Please enter the staff number", Title:="Load Staff Data")
Open Tfile For Input As #f
Do While Not EOF(f)
IngLine = IngLine + 1
Line Input #f, strLine
If InStr(1, strLine, staffdat, vbBinaryCompare) > 0 Then
MsgBox "Search string found in line" & IngLine, vbInformation
bInFound = True
Exit Do
End If
Loop
Close #f
If Not bInFound Then
MsgBox "Search string not found", vbInformation
End If
End Sub
我建議您研究Split()函數。
我認為您的代碼最終會像#17中的以下內容一樣(您將不得不修剪/確定在哪里“標記化”行,具體取決於輸入文件的外觀):
If InStr(1, strLine, staffdat, vbBinaryCompare) > 0 Then
foundArr = Split(strLine, " ")'change " " to whatever fits your needs
For i = LBound(foundArr) to UBound(foundArr)
'enter each string into a cell, etc
Next i
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.