如何用VBA在excel中写公式?
我要用vba在excel中写公式,如a10=sum(ai,aj),其中i,j是变量,要在运行中才确定.
该公式要如何写?
cells(1,1)="=sum(" & toLetter(col1) & row1 & ":" & toLetter(col2) & row2 & ")"
function toLetter(col as integer) as string
toLetter=vba.chr$(vba.asc("a")+col-1)
end function
注意: toLetter()只能转换26列以内的数字,如果要200列以上的,自己写一个转换函数吧