使用vba / excel / c将工作表分成多个文件的解决scheme#

我想将工作表分成多个文件。

我有一个约10,000行的工作表。 有花哨的格式,条件格式,漂亮的颜色,我想保留所有这些属性。

我需要把这个工作表分开。

input将是:

+-------+----+----+----+----+ | Alex | 45 | 6 | 23 | 56 | | Alex | 61 | 47 | 56 | 56 | | Liza | 49 | 70 | 34 | 37 | | Alex | 33 | 30 | 22 | 39 | | Tommy | | 66 | 62 | 29 | | Liza | | 38 | 49 | 80 | | Alex | 23 | 56 | 56 | 39 | | Liza | 32 | 46 | 40 | 43 | | Liza | | 90 | 24 | 38 | | Tommy | 38 | 10 | 52 | 23 | | Nancy | 35 | 36 | 23 | 25 | +-------+----+----+----+----+ 

和输出将是这样的单独的文件(请记住,我想保留所有花哨的格式,因此该解决scheme直接与Excel中,而不是只与CSV(因为CSV无法保留格式))工作)

最终产品:

 +------+----+----+----+----+ | | | | | | | Alex | 45 | 6 | 23 | 56 | | Alex | 61 | 47 | 56 | 56 | | Alex | 33 | 30 | 22 | 39 | | Alex | 23 | 56 | 56 | 39 | +------+----+----+----+----+ 

 +------+----+----+----+----+ | | | | | | | Liza | 49 | 70 | 34 | 37 | | Liza | | 38 | 49 | 80 | | Liza | 32 | 46 | 40 | 43 | | Liza | | 90 | 24 | 38 | +------+----+----+----+----+ 

 +-------+----+----+----+----+ | | | | | | | Nancy | 35 | 36 | 23 | 25 | +-------+----+----+----+----+ 

 +-------+----+----+----+----+ | | | | | | | Tommy | | 66 | 62 | 29 | | Tommy | 38 | 10 | 52 | 23 | +-------+----+----+----+----+ 

该解决scheme可以是VBA / .NET的组合。 请注意,我需要多个文件作为输出。

什么是最快捷的方式来得到这个工作? 非常感谢任何input!

请注意,这是Excel 2007及更高版本

我之前做过这个。

你可以使用这个代码:

 Option Explicit Sub getInformations() Dim varName As String Application.ScreenUpdating = False 'Replace Tabelle1 with the name of your sheet where the Informations are Worksheets("Tabelle1").Select Worksheets("Tabelle1").Copy After:=Sheets("Tabelle1") Sheets("Tabelle1 (2)").Select Sheets("Tabelle1 (2)").Name = "Temp" Do Until Range("A1").Value = vbNullString varName = Range("A1").Value Workbooks.Add 'Change the Path where you want to save the File ActiveWorkbook.SaveAs ("C:\Documents and Settings\vgellhom\Desktop\" & varName & ".xls") 'Change The Name of the Excel Workbopk to the Name of the Workbook with the Names Workbooks("Data.xls").Activate Sheets("Temp").Select varName = Range("A1").Value Do While True Cells.Find(What:=varName).Activate Range(ActiveCell.Row & ":" & ActiveCell.Row).Select Selection.Copy Workbooks(varName & ".xls").Activate ActiveSheet.Paste ActiveCell.Offset(1, 0).Activate 'Change The Name of the Excel Workbopk to the Name of the Workbook with the Names Workbooks("Data.xls").Activate Sheets("Temp").Select Selection.Delete Shift:=xlUp If Not Cells.FindNext(After:=ActiveCell) Is Nothing Then Cells.Find(What:=varName).Activate Else Exit Do End If Loop Workbooks(varName & ".xls").Activate 'Change the Path where you want to save the File Application.DisplayAlerts = False ActiveWorkbook.Save Application.DisplayAlerts = True Workbooks(varName & ".xls").Close Loop Application.DisplayAlerts = False Sheets("Temp").Delete Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub 

希望能帮助你…

由于Excel格式化通常是a **中的一大难题,因此我build议您尝试以下解决scheme:

  1. 计算并存储所有唯一的密钥。
  2. 为每个键创build一个文件的副本(如file_Alex.xls[x]file_Liza.xls[x]等)。
  3. 处理每个文件,删除所有非关键行,从而留下所有关键条目。 另外,因为您只删除整行,所有文件中的格式都被保留。

这是非常不优化的,但也是非常简单的解决scheme。 如果是一次性工作,那应该没问题。