如何根据单元格值格式化多维数组?
How to format a multidimensionnal array depending on it's cell values?
我正在尝试在我的 Excel sheet 中格式化一个数组。 goel 有点做 SUMIF
的相反操作,对于我的 table 的每个元素及其编号 x
,我想创建此元素的 x
行在另一个 table 中。
由于屏幕截图比长对话框更明确,因此这是我想要实现的目标:
如果有 0
个水果,则不应在 GOAL
table 中显示。
Base
和 Goal
table 很难写在我的 excel sheet 中作为示例, Current Result
table 是用这个公式做的:
法语版(我用的是法语Excel):
{=SIERREUR(
INDEX(
B:B0;
PETITE.VALEUR(
SI(
SI(
($C:$C0>0);
VRAI;
FAUX
);
LIGNE(B:B0)-LIGNE(B)+1
);
LIGNES(B:B5)
)
);
""
)}
英文版(未测试):
{=IFERROR(
INDEX(
B:B0;
SMALL(
IF(
IF(
($C:$C0>0);
TRUE;
FALSE
);
ROW(B:B0)-ROW(B)+1
);
ROWS(B:B5)
)
);
""
)}
你能给我一些关于如何实现这一点的提示吗?我有什么办法可以不使用 VBA 而只使用公式吗?
注:
我在工作中被要求这样做,我一生中从未使用过 Excel 并且对 VBA 一无所知。这就是为什么我对这项任务有点迷茫。我通常使用 Python 或 C++ 编写代码。我正在使用 Excel 2010.
我使用 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
这是输出:
基于 Matt 在 duplicate 中的回答的解决方案。
我正在尝试在我的 Excel sheet 中格式化一个数组。 goel 有点做 SUMIF
的相反操作,对于我的 table 的每个元素及其编号 x
,我想创建此元素的 x
行在另一个 table 中。
由于屏幕截图比长对话框更明确,因此这是我想要实现的目标:
如果有 0
个水果,则不应在 GOAL
table 中显示。
Base
和 Goal
table 很难写在我的 excel sheet 中作为示例, Current Result
table 是用这个公式做的:
法语版(我用的是法语Excel):
{=SIERREUR(
INDEX(
B:B0;
PETITE.VALEUR(
SI(
SI(
($C:$C0>0);
VRAI;
FAUX
);
LIGNE(B:B0)-LIGNE(B)+1
);
LIGNES(B:B5)
)
);
""
)}
英文版(未测试):
{=IFERROR(
INDEX(
B:B0;
SMALL(
IF(
IF(
($C:$C0>0);
TRUE;
FALSE
);
ROW(B:B0)-ROW(B)+1
);
ROWS(B:B5)
)
);
""
)}
你能给我一些关于如何实现这一点的提示吗?我有什么办法可以不使用 VBA 而只使用公式吗?
注: 我在工作中被要求这样做,我一生中从未使用过 Excel 并且对 VBA 一无所知。这就是为什么我对这项任务有点迷茫。我通常使用 Python 或 C++ 编写代码。我正在使用 Excel 2010.
我使用 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
这是输出:
基于 Matt 在 duplicate 中的回答的解决方案。