好的,我想我已经阅读了所有出现的选项,但并没有完全从已经回答的选项中得到答案——如果已经回答,请原谅我,我只是很特别。
我想做的是以下几点:
从具有固定 (62) 标题的主工作簿中,能够运行宏/VBA,这将使我能够打开文件 (.csv),从该文件中获取列并将它们放在主表上的相应标题下。
.csv 文件肯定会有与主文件匹配的列标题,但它可能不在同一序列中。
您的帮助将不胜感激。
缺口
这是到目前为止我有帮助的代码......
Sub CopyCSV()
'' Find out how many rows are on the CSV sheet
LRCSV = Sheet1.UsedRange.Rows.Count
'' Find out how many columns are on the Data sheet
LCData = Sheet2.UsedRange.Columns.Count
For x = 2 To LRCSV
'' Find the last row and add one to get the first blank row
LRData = Sheet2.UsedRange.Rows.Count + 1
Sheet2.Activate
'' Finds the columns by the headers
If FirstN = "" Then
For y = 1 To LCData
If Cells(1, y).Value = "First Name" Then FirstN = y
If Cells(1, y).Value = "Surname" Then SurN = y
If Cells(1, y).Value = "Email" Then Email = y
If Cells(1, y).Value = "Telephone Number" Then TelN = y
Next y
End If
Sheet1.Activate
Sheet2.Cells(LRData, FirstN).Value = Sheet1.Cells(x, "A").Value
Sheet2.Cells(LRData, SurN).Value = Sheet1.Cells(x, "B").Value
Sheet2.Cells(LRData, Email).Value = Sheet1.Cells(x, "C").Value
Sheet2.Cells(LRData, TelN).Value = Sheet1.Cells(x, "D").Value
Next x
End Sub
它是我正在努力解决的按列查找部分...