2014-01-09 70 views
0

让我先开始......我通常不使用excel,所以这里总是新手。将目标信息从一张纸移植到另一张

片1奠定了像这样...

(日期排序),(数量),(介绍),(供应商),(原因)

在片材2,我想成为能够让它从供应商栏中拉出一个特定的供应商,并将其所有与其相关的栏移动到工作表2上。

因此,我可以快速查看sheet2,sheet3等...并查看已订购和用于一个特定的供应商,并帮助我跟踪每个供应商的订单情况。

预先感谢您的任何和所有答复。

+0

每个供应商只有一行吗? –

+0

1列,列出各个供应商。将复制并粘贴下面的行。 – user3177686

+0

2013年12月19日 11-11990 /飞机翼尖NAVLIGHT清晰透镜盖\t飞机云杉\t STOCK – user3177686

回答

0

这里有一个宏观的解决方案:

Sub create_sheets_with_data() 
     'assumes that "main" sheet contains data with a header row 
     'needs to be run from "main" sheet 

     'delete all sheets whose name contains "viewport" 
     Application.DisplayAlerts = False 
     For i = Sheets.Count To 1 Step -1 
      If InStr(1, Sheets(i).Name, "viewport", vbTextCompare) > 0 Then Sheets(i).Delete 
     Next i 
     Application.DisplayAlerts = True 

     'get last row 
     last_row = Cells.SpecialCells(xlCellTypeLastCell).Row 

     'sort by vendor 
     Rows("1:1").Select 
     ActiveWorkbook.Worksheets("main").Sort.SortFields.Clear 
     ActiveWorkbook.Worksheets("main").Sort.SortFields.Add Key:=Range("D2:D" & last_row) _ 
      , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal 
     With ActiveWorkbook.Worksheets("main").Sort 
      .SetRange Range("A1:E" & last_row) 
      .Header = xlYes 
      .MatchCase = False 
      .Orientation = xlTopToBottom 
      .SortMethod = xlPinYin 
      .Apply 
     End With 

     'for each vendor in "main" sheet, create a viewport to the data 
     Dim r As Long, dest_row As Long 
     r = 2 
     last_vendor = "" 
     cur_vendor = Range("d" & r).Value 
     viewport_num = 0 
     Do While Not cur_vendor = "" 
      If cur_vendor = last_vendor Then 
       'add current line to current viewport tab 
       copy_line r, dest_row 
       dest_row = dest_row + 1 
      Else 
       'create new viewport, copy over header, and copy current line 
       If viewport_num > 0 Then Cells.EntireColumn.AutoFit 
       viewport_num = viewport_num + 1 
       Sheets.Add After:=Sheets(Sheets.Count) 
       Sheets(Sheets.Count).Name = "viewport " & viewport_num 
       copy_line 1, 1 'header 
       copy_line r, 2 'current line 
       dest_row = 3 
      End If 
      r = r + 1 
      last_vendor = cur_vendor 
      cur_vendor = Sheets("main").Range("d" & r).Value 
     Loop 
     If viewport_num > 0 Then Cells.EntireColumn.AutoFit 

     Sheets("main").Activate 
    End Sub 

    Sub copy_line(src_r As Long, dest_r As Long) 
     'copies line from "main" sheet to active sheet 
     Sheets("main").Rows(src_r & ":" & src_r).Copy 
     Range("a" & dest_r).Select 
     ActiveSheet.Paste 
    End Sub 

我有一个宏观的解决方案去,而不是公式,因为它在我看来,你可以有新的厂商加入到该数据在未来的某一时刻。为了避免必须手动制作纸张,我避免了公式。

请记住,此解决方案将使您的主表按供应商排序。

我希望有帮助〜

+0

非常感谢您的帮助。我会试试这个,并让你知道它是如何解决我的。 – user3177686

+0

不客气,祝你好运。 – chrono

+0

我对这一切都没有任何运气。我对excel不够熟悉。而我之上的其他人并不如此。 – user3177686

相关问题