我有一个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