复制 Excel 中的公式,方法是将单元格拖到另一个单元格

Copy the formula in Excel as it is done by dragging the cell over to another

For i = 1 To staffelRange.Rows.Count
   .DataBodyRange.Cells(i, countHeader).Formula = staffelRange.Cells(i).Formula
Next

the code works as intended and copies the formulas from my range into the desired range in my table. first to the formula, the formula always refers to the column header and the cell left of it, if i copy the code now with my function from column 1 to for example column 4, the formula still refers to column 1 instead of column 4. but if i copy it by dragging the formula over to the other cell, the formula adapts. How can I achieve such an adjustment in my code? Formula: =$G39*(1+SVERWEIS(Stückpreise_neu_19[[#Kopfzeilen];[Staffel1]];Rabattstaffel_new_24;2;FALSCH))

如果公式除单元格引用外始终相同,您只需将公式写入 sheet 作为字符串值,并为正确的行号添加一个变量。

类似...

For i = 1 To staffelRange.Rows.Count
   .DataBodyRange.Cells(i, countHeader).Formula = "=$G" & i & "*1+SVERWEIS(Stückpreise_neu_19[[#Kopfzeilen];Staffel1]];Rabattstaffel_new_24;2;FALSCH))"
Next

这是假设您的变量 i 代表公式的正确行号(据我所知是正确的)。