用户定义的连接
我正在努力扩展我的年度计划文件,给我更多的信息。 目前,但我卡住了。
我目前的表格布局如下:
我需要创build一个连接客户端名称与每个列标题的第二个工作表,其中有一个“是”值,作为它自己的单独的行。
新表中的示例1将变为:
Example 1 - Annuals Example 1 - Xero Fee
我已经尝试了复制和粘贴macros,基于数量列包含文本行。 这给了一个新的工作表所需的客户名称数量,但我无法解决如何包括这个问题的“连接”部分。
Public Sub CopyData() ' 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 ' Set this for the range where the Quantity column exists. This works only if there are no empty cells Set rngQuantityCells = Range("G1", Range("G1").End(xlDown)) 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 Range(rngSinglecell.Address).EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1) ' The above line finds the next empty row. Next End If End If Next End Sub
如果你的目标是从这个得到:
… 这个 (或那个 ):
那么你想做什么就叫做Unpivot 。
如何Unpivot“crosstab样式”数据:
你可以find我在一周前回答的问题上写出的步骤,这里有更详细的解释和步骤 。
让我知道如果你有任何问题!
是的,也许我以此为借口来练习使用Screen2Gif ,但它确实有助于演示一个观点! 🙂