字符串引用和单元格引用
Quotes for String and Cell Reference
我需要将 excel 公式转换为 VBA 代码,但是我尝试了很多次,但没有成功。
下面是我需要转换的公式。
=IF(G7959<0, "Delivered to end customer " & E7959, "To be delivered to end customer " & E7959)
下面是我试过但没有成功,参数'IC_inventory_new_row'代表一个可变的行索引。谁能帮忙看看并指教一下?
IC_inventory_WS.Cells(IC_inventory_new_row, 15).Formula = "=IF(G" & IC_inventory_new_row + 1 & "<0, " & "Delivered to end customer" & "E" & IC_inventory_new_row & "," & "To be delivered to end customer " & "E" & IC_inventory_new_row & ")"
请试试:
IC_inventory_WS.Cells(IC_inventory_new_row, 15).formula = "=IF(G" & IC_inventory_new_row + 1 & _
"<0, ""Delivered to end customer ""&E" & IC_inventory_new_row & _
", ""To be delivered to end customer ""&E" & IC_inventory_new_row & ")"
但是可以写成不需要迭代的方式。我的意思是,一次把它放到所有范围内。如果我正确理解需要什么,请尝试这种方式,它应该可以满足您的需求:
IC_inventory_WS.Range("O2:O" & lastRow).formula = "=IF(" & Range("G2").address(0, 0) & _
"<0, ""Delivered to end customer ""&" & Range("E2").address(0, 0) & _
", ""To be delivered to end customer ""&" & Range("E2").address(0, 0) & ")"
如果不是,请根据您的实际需要说明它的作用。
我需要将 excel 公式转换为 VBA 代码,但是我尝试了很多次,但没有成功。 下面是我需要转换的公式。
=IF(G7959<0, "Delivered to end customer " & E7959, "To be delivered to end customer " & E7959)
下面是我试过但没有成功,参数'IC_inventory_new_row'代表一个可变的行索引。谁能帮忙看看并指教一下?
IC_inventory_WS.Cells(IC_inventory_new_row, 15).Formula = "=IF(G" & IC_inventory_new_row + 1 & "<0, " & "Delivered to end customer" & "E" & IC_inventory_new_row & "," & "To be delivered to end customer " & "E" & IC_inventory_new_row & ")"
请试试:
IC_inventory_WS.Cells(IC_inventory_new_row, 15).formula = "=IF(G" & IC_inventory_new_row + 1 & _
"<0, ""Delivered to end customer ""&E" & IC_inventory_new_row & _
", ""To be delivered to end customer ""&E" & IC_inventory_new_row & ")"
但是可以写成不需要迭代的方式。我的意思是,一次把它放到所有范围内。如果我正确理解需要什么,请尝试这种方式,它应该可以满足您的需求:
IC_inventory_WS.Range("O2:O" & lastRow).formula = "=IF(" & Range("G2").address(0, 0) & _
"<0, ""Delivered to end customer ""&" & Range("E2").address(0, 0) & _
", ""To be delivered to end customer ""&" & Range("E2").address(0, 0) & ")"
如果不是,请根据您的实际需要说明它的作用。