我正在尝试扩展年度计划文档,以便向我提供更多信息。目前我被卡住了。
我目前的工作表布局如下:
我需要创建第二个工作表,将客户端名称与每个列标题连接在一起,其中有一个“是”值,作为它自己的单独行。
新表中的示例1 将变为:
Example 1 - Annuals Example 1 - Xero Fee
我尝试过根据计算包含文本的行的数量列复制并粘贴宏。这在新表中给出了所需数量的客户名称,但我无法弄清楚如何将此问题的“连接”部分包含在其中。
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
答案 0 :(得分:3)
您可以找到a question I answered a week ago上写出的步骤,还有更多detailed explanation and steps over here。
如果您有任何疑问,请与我联系!
是的,也许我以此为借口练习使用Screen2Gif,但它确实有助于演示一点! : - )