2016-12-02 32 views
0

进出口寻找自动化其重复我们客户的名字对一个预先定义的一个月,并导致列的表创建一个解决方案。加入无关的数据表中的

我已经通过VBA试图循环,但结果很慢,无法使用。我也尝试使用Microsoft查询并添加这两个表,只是不加入表。这将一直运行,直到在基础数据中进行更新,这会导致第二个表消失。我正在寻找稳定的解决方案来维持结构。

所得表用于建立其用于计数在其他工作表匹配条目的串连式。

数据的一个例子如下:

Customer names: 
Adam 
Anne 

Month Result 
Jan  Pass 
Jan  Fail 
Jan  Exclude 
Feb  Pass 
Feb  Fail 
Feb  Exclude 

所需的输出:

Name Month Result 
Adam Jan  Pass 
Adam Jan  Fail 
Adam Jan  Exclude 
Adam Feb  Pass 
Adam Feb  Fail 
Adam Feb  Exclude 
Anne Jan  Pass 
Anne Jan  Fail 
Anne Jan  Exclude 
Etc 

任何帮助将不胜感激!

回答

0

试试这个,希望你能找出细胞refernces

Sub tabulate() 
Dim custNames As Range 
Dim data As Range 

Set custNames = Range("A2:A3") 
Set data = Range("A6:B11") 

For i = 1 To custNames.Rows.Count 
    For j = 1 To data.Rows.Count 
     Range("E1").Offset((i - 1) * data.Rows.Count + (j - 1), 0) = custNames(i, 1) 
     Range("F1").Offset((i - 1) * data.Rows.Count + (j - 1), 0) = data(j, 1) 
     Range("G1").Offset((i - 1) * data.Rows.Count + (j - 1), 0) = data(j, 2) 
    Next 
Next 
End Sub 
0

这将努力增加各种不同的组合:

Sub compare() 
    Dim CustNames() 
    Dim MonthName, count, row 
    ReDim CustNames(1) 
    CustNames(0) = Range("A2").Value 
    CustNames(1) = Range("A3").Value 
    row = 0 
    Range("C1").Select 
    For j = 1 To 12 Step 1 
     count = 0 
     For i = 0 To (UBound(CustNames) + 0.5) * 3 Step 3 
      Select Case j 
       Case 1 
        MonthName = "Jan" 
       Case 2 
        MonthName = "Feb" 
       Case 3 
        MonthName = "Mar" 
       Case 4 
        MonthName = "Apr" 
       Case 5 
        MonthName = "May" 
       Case 6 
        MonthName = "Jun" 
       Case 7 
        MonthName = "Jul" 
       Case 8 
        MonthName = "Aug" 
       Case 9 
        MonthName = "Sep" 
       Case 10 
        MonthName = "Oct" 
       Case 11 
        MonthName = "Nov" 
       Case 12 
        MonthName = "Dec" 
      End Select 
      ActiveCell.Offset(row, 0).Range("A1").Value = CustNames(count) 
      ActiveCell.Offset(row + 1, 0).Range("A1").Value = CustNames(count) 
      ActiveCell.Offset(row + 2, 0).Range("A1").Value = CustNames(count) 
      ActiveCell.Offset(row, 1).Range("A1").Value = MonthName 
      ActiveCell.Offset(row + 1, 1).Range("A1").Value = MonthName 
      ActiveCell.Offset(row + 2, 1).Range("A1").Value = MonthName 
      ActiveCell.Offset(row, 2).Range("A1").Value = "Pass" 
      ActiveCell.Offset(row + 1, 2).Range("A1").Value = "Fail" 
      ActiveCell.Offset(row + 2, 2).Range("A1").Value = "Exclude" 
      count = count + 1 
      row = row + 3 
     Next i 
    Next j 
End Sub