将行从不同的Excel文件复制到列中

我需要从一个文件复制一些行中的一些元素到另一个文件中的一些不同的单元格。 这是起始文件:

output.csv I_30_2_02_02_1.csv 7 239 I_30_2_02_02_1.csv 7 174 I_30_2_02_02_1.csv 7 458 I_30_2_02_02_1.csv 7 156 I_30_2_02_02_1.csv 7 163 

这是结束文件:

 Results.xls I_30_2_02_02_1.csv 7 239 7 174 7 458 7 156 7 163 

我必须做900次

你知道我该怎么做? 我尝试粘贴特殊,但它重复的元素。 感谢帮助。

我不确定你想把这些值7,239,…等等粘贴在一行中。 但是,如果这个假设是正确的,并且假设你的数据在Sheet4中,那么在单元格B2中使用的公式是(为了获得前7个)

 =INDEX(Sheet4!$B$1:$C$12,TRUNC(COLUMN()/2),MOD(COLUMN(),2)+1) 

您可以将公式拖到900列。 您的XLS中的A1可以直接链接到CSV中的A1。

这应该给你所有的价值在一行。

查看所附的Excel文件的示例截图。 下面仅重新粘贴数值,仅供说明之用。 1

注意:如果您不确定您的input是否有效,则索引函数$ B $ 1:$ C $ 12中的公式可以概括为$ B:$ C。

使用此代码来遍历目录中的所有.csv文件。 join你的特定的string操作或任何到中间部分。 如果您需要帮助,请添加评论…

 'KMZ 02/05/20105 Option Explicit Private Sub whatever() 'PURPOSE: To loop through all specified filetypes in a user specified folder and perform a set task on them 'typical excel variables Dim wb As Workbook Dim myPath As String Dim myFile As String Dim myExtension As String Dim FldrPicker As FileDialog 'classic loopers Dim i, j, k As Long 'Optimize Macro Speed Application.ScreenUpdating = False Application.EnableEvents = False Application.Calculation = xlCalculationManual 'Retrieve Target Folder Path From User Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker) With FldrPicker .Title = "Select A Target Folder - {Where your *.csv's are saved...}" .AllowMultiSelect = False If .Show <> -1 Then GoTo NextCode myPath = .SelectedItems(1) & "\" End With 'In Case of Cancel NextCode: myPath = myPath If myPath = "" Then GoTo ResetSettings 'Target File Extension (must include wildcard "*") myExtension = "*.csv" 'Target Path with Ending Extention myFile = Dir(myPath & myExtension) 'Loop through each Excel file in folder Do While myFile <> "" Debug.Print "myFile = " & myFile 'Set variable equal to opened workbook Set wb = Workbooks.Open(Filename:=myPath & myFile) 'Do your stuff here, man. With wb.Worksheets(1) 'add in your string manipulation / cell dumping here 'with a few lines End With 'Close opened *.csv, do not save wb.Saved = True 'fake a save, so message box doesnt pop up wb.Close SaveChanges:=False 'Get next file name myFile = Dir Loop 'Message Box when tasks are completed MsgBox "Task Complete! Review in your xlWorkbook!" ResetSettings: 'Reset Macro Optimization Settings Application.EnableEvents = True Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Sub