2015-04-14 66 views
0

我想在我的Excel表格中格式化一个数组。对于我的表中的每个元素,它的编号是,我想在另一个表中创建此元素的x行,这与SUMIF相反。 作为截图可以比一个长对话更加明确,这里就是我想达到什么:Excel table如何格式化一个多维数组,取决于它的单元格值?

如果有水果的0出现时它不应该被显示在GOAL表。

法语版本(我使用的是法国的Excel):

BaseGoal表硬写在我的Excel工作表,并作为一个例子,Current Result表是用这个公式由

{=SIERREUR(
INDEX(
    B$5:B$100; 
    PETITE.VALEUR(
    SI(
    SI(
    ($C$5:$C$100>0); 
    VRAI; 
     FAUX 
    ); 
    LIGNE(B$5:B$100)-LIGNE(B$5)+1 
    ); 
    LIGNES(B$5:B5) 
) 
); 
"" 
)} 

英文版本(没有带测试吧):

{=IFERROR(
INDEX(
    B$5:B$100; 
    SMALL(
    IF(
    IF(
    ($C$5:$C$100>0); 
    TRUE; 
     FALSE 
    ); 
    ROW(B$5:B$100)-ROW(B$5)+1 
    ); 
    ROWS(B$5:B5) 
) 
); 
"" 
)} 

你能给我一些提示,告诉我如何实现这个目标吗?我有没有办法做到这一点,而不使用VBA,只有公式?

说明: 我被要求在工作中这样做,我从未在我的整个生活中使用过Excel,而对VBA一无所知。这就是为什么我有点失落这个任务。我通常使用Python或C++编写代码。我使用Excel 2010中

+0

看起来像我在提出这个问题之前所做的研究不够好,这里是一个可能的[重复](http://stackoverflow.com/questions/25395454/excel-vba-automation-copy-row-x-数的次基 - 导通单元值)。要尝试根据此找到我自己的解决方案。 – DrHaze

+0

好的。让我知道如果你仍然决定在阅读该文章后想要一个纯粹的基于配方的解决方案。 –

+0

我设法使用VBA来做我想要的,谢谢你的时间。 – DrHaze

回答

0

我设法用VBA来实现我的目标,这里是我使用的代码:

Public Sub GenerateTable() 
    ' This routing will copy rows based on the quantity to a new sheet. 
    Dim rngSinglecell As Range 
    Dim rngQuantityCells As Range 
    Dim intCount As Integer 
    Dim countCell As Integer 

    ' Set this for the range where the Quantity column exists. This works only if there are no empty cells 
    Set rngQuantityCells = Sheets("Feuil3").Range("C5", Sheets("Feuil3").Range("C5").End(xlDown)) 

    countCell = 4 
    For Each rngSinglecell In rngQuantityCells 
     ' Check if this cell actually contains a number 
     If IsNumeric(rngSinglecell.Value) Then 
      ' Check if the number is greater than 0 
      If rngSinglecell.Value > 0 Then 
       ' Copy this row as many times as .value 
       For intCount = 1 To rngSinglecell.Value 
        ' Copy the row into the next emtpy row in sheet2 
        countCell = countCell + 1 
        Intersect(Range(rngSinglecell.Address).EntireRow, Columns("B:D")).Copy Destination:=Sheets("Feuil3").Range("G" & CStr(countCell)) 
       Next 
      End If 
     End If 
    Next 
End Sub 

这里是输出:

Result

解决方案基于马特在duplicate的回答。

相关问题