我有一個Excel文件:提取數據
Excel.xls
Code date start end
2301 12/08/1993 08:02 08:17
4221 12/08/1993 09:04 09:25
2312 12/08/1993 10:02 10:28
1284 19/09/1994 11:02 11:21
2312 19/09/1994 15:57 16:20
1284 23/06/1995 17:12 17:35
2312 22/06/1996 13:14 13:32
4221 22/06/1996 15:53 16:13
4221 05/05/1999 08:06 08:22
2418 05/05/1999 08:10 08:33
2301 05/05/1999 09:12 09:37
2301 05/05/1999 09:28 10:28
2301 05/05/1999 13:28 13:38
問題:
的問題是,以提取數據從excel文件到另一個由Code
連接的行?
希望的解決方案:
從Excel中導入數據文件到另一個或工作簿時,通過Code
行的數目接合與數據有關的名片,例如在片材2301
我可以具有唯一的數據人誰該代碼在Excel文件:
Sheet2301
Code date start end
2301 05/05/1999 09:12 09:37
2301 05/05/1999 09:28 10:28
2301 05/05/1999 13:28 13:38
.... ...... .... ....
林AB例如VBA中的內幕,所以我花了幾天的時間找到解決方案。
編輯:
其實我有不同的CSV文件,我導入到使用此VBA代碼的唯一工作表:
Option Explicit
Sub ImportCSV()
Dim strSourcePath As String
Dim strDestPath As String
Dim strFile As String
Dim strData As String
Dim x As Variant
Dim Cnt As Long
Dim r As Long
Dim c As Long
Application.ScreenUpdating = False
'Change the path to the source folder accordingly
strSourcePath = "path to csv files\"
If Right(strSourcePath, 1) <> "\" Then strSourcePath = strSourcePath & "\"
'Change the path to the destination folder accordingly
strDestPath = "path to csv files\"
If Right(strDestPath, 1) <> "\" Then strDestPath = strDestPath & "\"
strFile = Dir(strSourcePath & "*.csv")
Do While Len(strFile) > 0
Cnt = Cnt + 1
If Cnt = 1 Then
r = 1
Else
r = Cells(Rows.Count, "A").End(xlUp).Row + 1
End If
Open strSourcePath & strFile For Input As #1
If Cnt > 1 Then
Line Input #1, strData
End If
Do Until EOF(1)
Line Input #1, strData
x = Split(strData, ",")
For c = 0 To UBound(x)
Cells(r, c + 1).Value = Trim(x(c))
Next c
r = r + 1
Loop
Close #1
Name strSourcePath & strFile As strDestPath & strFile
strFile = Dir
Loop
Application.ScreenUpdating = True
If Cnt = 0 Then _
MsgBox "No CSV files were found...", vbExclamation
End Sub
和代碼工作很細,所以我必須通過加入該數據在不同的電流表中(正如我之前解釋的)?
'花了幾天'如果這是真的,我可能會建議你僱用一個人XD – findwindow
在這幾天裏,我希望你已經找到*一些你可以嘗試的代碼,或者至少是一個想法。如果是這樣,請發佈該代碼! – BruceWayne
@findwindow問題是我非常喜歡VBA Excel初學者,很抱歉! – Yassou