单个Excel工作表到多个工作表,基于特定的列值

时间:2018-05-09 11:40:48

标签: excel vba key row

我有以下问题:

我有一个类型的电子表格:

Field1    Field2     Field3    Field4
NameA     AddressA   KeyA      ValueA
NameB     AddressB   KeyA      ValueB
NameD     AddressD   KeyA      ValueD
NameE     AddressE   KeyB      ValueE
NameC     AddressC   KeyB      ValueC
NameF     AddressF   KeyC      ValueF
.... (200k entries)

我想阅读工作表,并创建一些单独的Excel工作簿,其中只有一个工作表,每个工作表包含ie:

Workbook1/Sheet1: (Workbookname ie KeyA.xlsx)
Field1    Field2     Field3    Field4
NameA     AddressA   KeyA      ValueA
NameB     AddressB   KeyA      ValueB
NameD     AddressD   KeyA      ValueD

Workbook2/Sheet1: (Workbookname ie KeyB.xlsx)
Field1    Field2     Field3    Field4
NameC     AddressC   KeyB      ValueC
NameE     AddressE   KeyB      ValueE

Workbook3/Sheet1: (Workbookname ie KeyC.xlsx)
Field1    Field2     Field3    Field4
NameF     AddressF   KeyC      ValueF

第一行必须存在于所有生成的工作簿中。他们对Field3值进行了排序,这是我在c:

中的逻辑
main(excel_file)
{
   open(excel_file, r)
   header = read(excel_file)
   first_line = true

   while not eof(excel_file)
  {
  line_cur = read(excel_file)

  if first_line
  {
     office = get_office(line_cur)
     office_file = open(name=office, w)

     write(office_file, header)
     write(office_file, line_cur)

     line_prv = line_cur
     first_line = false
     continue
  }

  office_cur = get_office(line_cur)
  office_prv = get_office(line_prv)

  // If same group.
  if office_cur = office_prv
  {
     write(office_file, line_cur)

     line_prv = line_cur
     continue
  }

  // If different group.
  if office_cur != office_prv
  {
     close(office_file)
     office_file = open(name=office_cur, w)

     write(office_file, header)
     write(office_file, line_cur)

     line_prv = line_cur
     continue
  }
   }   // while end.

   close(office_file)
   close(excel_file)
}

你能帮助我弄清楚如何在VBA中实现这个逻辑吗?零经验。先感谢您。

0 个答案:

没有答案