这对于实验VBA开发人员/用户来说可能是一段相当简单的代码,但即时新的编程Im已经停留在这个任务上几天了:(我需要的是将一个公式应用到用户定义的范围内(如果可能的话)或者用“for-each next”或“for next”循环遍历它,并且我为每次试图尝试的每一次尝试都会出错。任何人都可以帮助我出这个问题,请.... thxs非常提前将公式应用于整个范围
比方说,该公式是一些容易为F = M * A,是“M”我的选择范围
下面的代码选择范围:
Option Base 1
Sub KVmodel()
'Select the data points from the excel spreadsheet
Dim A, B As Range
Set A= Application.InputBox("Select A Range", "Select a range", Type:=8)
Set B= Application.InputBox("Select B Range", "Select a range", Type:=8)
'Verify the lenght of the selected data
If A.Count = B.Count Then
MsgBox "Do you want to run the KV Model Adjustment?", vbYesNo
'Calculates F according to the values of the model
-
-
-
Else
MsgBox "The range sizes are different, please re-select the input data"
End If
End Sub
你想公式插入每个单元格或插入VBA计算公式的结果呢?你给出的公式例子,你说的是什么,一个怎么样?也是在整个范围内?或者它里面的一个单元格,对于一个单元格是相同 – NickSlash 2013-03-12 22:27:12
对不起,因为不是更精确,“a”意味着一个标量,并且整个想法将会生成另一个范围或数组,作为应用于所选范围的公式的结果。 PS:thxs为您的及时答案;) – 2013-03-12 22:35:31
所以你有3个范围? A,B和M(你选择的),你想用A和B做些什么,然后把结果放在M中?或者你有2个范围,A和B,对A做些什么并把结果放在B中? – NickSlash 2013-03-12 22:54:45