我不知道从哪里开始这个问题(可能是因为术语知识不足)。我有两个工作表,我将在Google表格中添加,我想生成第三个工作表(也在同一个Google表格文件中)。
https://docs.google.com/spreadsheets/d/1ALQlQhNugUnQzM5NdbFsLX_TlhV6BzT_1TDQKc6hD5I/edit?usp=sharing
我希望预算组工作表中的信息在每个公司的Balance工作表中向下显示,并在公司工作表中显示其公司代码。为这种交互编写一个宏是最好的还是可以用公式来做?提前致谢!如果我不清楚,请告诉我。
编辑:为了更清楚,我正在尝试根据预算组和公司工作表中的信息从头开始生成Balance工作表。
答案 0 :(得分:0)
对于您拥有简单键/值组合的公司,因此如果在[Balance]中您拥有公司名称并希望显示[Companies]代码表中的公司代码,则使用简单的VLOOKUP,例如
<%= f.fields_for :filters, OpenStruct.new(@lesson.filters) do |d| %>
(注意:通常情况会反过来......你有代码,想要扩展名称......在这种情况下,你必须在[公司]中反转列顺序,因为关键列必须在第1栏。)
预算组的情况并不是那么清楚,除了所有三个列的组合之外,这个列表可能没有唯一的密钥。
答案 1 :(得分:0)
我在Spioter Excel vba to create every possible combination of a Range找到了一个解决方案,这个解决方案非常有用!修改了脚本以满足我的需求和工作表,这不反映问题中的Google表单链接。谢谢Spioter!
Sub sub_CrossJoin()
Worksheets("Combinations").Range("A4:B2000").ClearContents
Dim rg_Legend As Range
Dim rg_Implementers As Range
Dim rg_RowLegend As Range
Dim rg_RowImplementers As Range
Dim rg_DestinationCol As Range
Dim rg_DestinationCell As Range
Dim int_PriorCombos As Long
Dim int_TotalCombos As Long
Dim int_LegendRowCount As Long
Dim int_ImplementersRowCount As Long
Dim int_ValueRepeats As Long
Dim int_ValueRepeater As Long
Dim int_ValueCycles As Long
Dim int_ValueCycler As Long
int_TotalCombos = 1
int_PriorCombos = 1
int_ValueRowCount = 0
int_ValueCycler = 0
int_ValueRepeater = 0
Set rg_Legend = Worksheets("Legend").Range("A8:A500")
Set rg_Implementers = Worksheets("Implementers").Range("A3:A50")
Set rg_DestinationCol = Worksheets("Combinations").Range("A4")
'Get total combos
int_LegendRowCount = 0
For Each rg_RowLegend In rg_Legend.Cells
If rg_RowLegend.Value = "" Then
Exit For
End If
int_LegendRowCount = int_LegendRowCount + 1
Next rg_RowLegend
int_TotalCombos = int_TotalCombos * int_LegendRowCount
int_ImplementersRowCount = 0
For Each rg_RowImplementers In rg_Implementers.Cells
If rg_RowImplementers.Value = "" Then
Exit For
End If
int_ImplementersRowCount = int_ImplementersRowCount + 1
Next rg_RowImplementers
int_TotalCombos = int_TotalCombos * int_ImplementersRowCount
int_LegendRowCount = 0
int_ImplementersRowCount = 0
'Calculate the repeats needed for each row value and then populate the destination
int_LegendRowCount = 0
For Each rg_RowLegend In rg_Legend.Cells
If rg_RowLegend.Value = "" Then
Exit For
End If
int_LegendRowCount = int_LegendRowCount + 1
Next rg_RowLegend
int_PriorCombos = int_PriorCombos * int_LegendRowCount
int_ValueRepeats = int_TotalCombos / int_PriorCombos
int_ValueCycles = (int_TotalCombos / int_ValueRepeats) / int_LegendRowCount
int_ValueCycler = 0
int_ValueRepeater = 0
Set rg_DestinationCell = rg_DestinationCol
For int_ValueCycler = 1 To int_ValueCycles
For Each rg_RowLegend In rg_Legend.Cells
If rg_RowLegend.Value = "" Then
Exit For
End If
For int_ValueRepeater = 1 To int_ValueRepeats
rg_DestinationCell.Value = rg_RowLegend.Value
Set rg_DestinationCell = rg_DestinationCell.Offset(1, 0)
Next int_ValueRepeater
Next rg_RowLegend
Next int_ValueCycler
Set rg_DestinationCol = rg_DestinationCol.Offset(0, 1)
For Each rg_RowImplementers In rg_Implementers.Cells
If rg_RowImplementers.Value = "" Then
Exit For
End If
int_ImplementersRowCount = int_ImplementersRowCount + 1
Next rg_RowImplementers
int_PriorCombos = int_PriorCombos * int_ImplementersRowCount
int_ValueRepeats = int_TotalCombos / int_PriorCombos
int_ValueCycles = (int_TotalCombos / int_ValueRepeats) / int_ImplementersRowCount
int_ValueCycler = 0
int_ValueRepeater = 0
Set rg_DestinationCell = rg_DestinationCol
For int_ValueCycler = 1 To int_ValueCycles
For Each rg_RowImplementers In rg_Implementers.Cells
If rg_RowImplementers.Value = "" Then
Exit For
End If
For int_ValueRepeater = 1 To int_ValueRepeats
rg_DestinationCell.Value = rg_RowImplementers.Value
Set rg_DestinationCell = rg_DestinationCell.Offset(1, 0)
Next int_ValueRepeater
Next rg_RowImplementers
Next int_ValueCycler
Set rg_DestinationCol = rg_DestinationCol.Offset(0, 1)
End Sub