VBA - 根据用户窗体条件插入两个新行,并复制单元格区域的 excel 公式

VBA - Insert two new rows based on Userform criteria and also copying the excel formula of a cell range

这个问题非常棘手,所以我添加了更多图片以便更好地理解这是我的 Excel sheet 在添加任何内容之前看起来像甘特图。

在此 Excel sheet 中,单元格由 Userform 填充,单元格值 "G3" 根据 "booked" 值单元格 "E4" 和 "F5"

所需输出:如何根据成员之间的 "Red" 和 "Blue" 在 列 A 中添加新的 "members"。重要的是甘特图也应该像其他成员一样添加。

输出应如下图所示:

我正在尝试使用以下代码的行插入方法,但它只是添加了一个新行,但没有满足我的要求。

Sub Insert()
    'Select and find where to insert new row
    ActiveSheet.Range("A:A").Find(What:=Me.cboteam.Value, LookIn:=xlFormulas, Lookat:=xlWhole)
    ActiveCell.EntireRow.Insert
    ActiveCell.Offset(1).EntireRow.Insert Shift:=xlDown,CopyOrigin:=xlFormatFromLeftOrAbove
 End Sub

试试这个:

Sub Insert()
    'Select and find where to insert new row
    Dim rngFound As Range: Set rngFound = ActiveSheet.Range("A:A").Find(What:=Me.cboteam.Value, LookIn:=xlFormulas, Lookat:=xlWhole)
    rngFound.Offset(1, 0).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    rngFound.Offset(1, 0).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Debug.Print rngFound.Offset(1, 0).Resize(2, 1).Address
    rngFound.Resize(3, 1).EntireRow.FillDown
 End Sub