1
テーブルの4つの特定の列(「Table1」)に数式を追加するには、入れ子になったループが必要です。これらの4つの追加の列( "colNames")の名前に関して、Forループが前のForループを模倣するようにしたいと思います。excelテーブルの列に式/データを入力するループが必要
このコードの一番下の部分はうまく動作しますが、ループにどのように組み込むかを知りたいと思います。ここで
Sub attStatPivInsertTableColumns_2()
Dim lst As ListObject
Dim currentSht As Worksheet
Dim colNames As Variant, formNames As Variant '<~~ NOTE: As Varient, this is your go to when working with arrays
Dim oLC As ListColumn, oLData As Variant
Dim i As Integer, d As Integer
Set currentSht = ActiveWorkbook.Sheets("Sheet1")
Set lst = ActiveSheet.ListObjects("Table1")
colNames = Array("AHT", "Target AHT", "Transfers", "Target Transfers")
For i = 0 To UBound(colNames)
Set oLC = lst.ListColumns.Add
oLC.Name = colNames(i)
Next i
***Below is the code that needs to be looped***
'lst.ListColumns("Target AHT").DataBodyRange.FormulaR1C1 = "=350"
'lst.ListColumns("Target Transfers").DataBodyRange.FormulaR1C1 = "=0.15"
'lst.ListColumns("AHT").DataBodyRange.FormulaR1C1 = "=([@[Inbound Talk Time (Seconds)]]+[@[Inbound Hold Time (Seconds)]]+[@[Inbound Wrap Time (Seconds)]])/[@[Calls Handled]]"
'lst.ListColumns("Transfers").DataBodyRange.FormulaR1C1 = "=[@[Call Transfers and/or Conferences]]/[@[Calls Handled]]"
End Sub
私はこれまでのところに行くのですが、私はおそらく明白な理由が何であるかのため、エラーに実行していますものです:
formNames = Array("=([@[Inbound Talk Time (Seconds)]]+[@[Inbound Hold Time (Seconds)]]+[@[Inbound Wrap Time (Seconds)]])/[@[Calls Handled]]", "=350", "=[@[Call Transfers and/or Conferences]]/[@[Calls Handled]]", "=0.15")
For d = 0 To UBound(formNames)
For i = 0 To UBound(colNames)
Set oLData = lst.ListColumns(i).DataBodyRange.FormulaR1C1 = "d"
Next i
Next d
私が間違っている場合は、私を修正してください。私はまだまだこれを試していない...これは私の質問でコード化された私の最初の私のループの必要性を否定するか?私が読んでいるところでは、 '.ListColumns.Add'にWITHステートメントが含まれているようです。 –
オリジナルでは(上記のように) 'oLC.NameBoldRange.FormulaR1C1 = r1c1s(i)'のようなもので 'oLC.Name = colNames(i)'の直後に別の行があります。 – Jeeped
よろしくお願いします、ありがとうございます。あなたはずっと効率的です。私は今までLBoundとUBoundの機能を見たことがありませんでした。うまくいった。 –