我需要编写一个电子表格,当您按下按钮时会添加一行数据并询问计算所需的参数,但我似乎无法让它填写下一行的数据?我是 excel 中宏的完整初学者,并且只在我的 uni 课程中为 matlab 完成了非常基本的编程。到目前为止,我的脚本如下:
Sub AddPosTol()
' AddPosTol Macro
Dim rngSeek As Range
Set rngSeek = Range("B1")
While rngSeek <> ""
'If the cell isn't empty, drop down one row:
rngSeek = rngSeek.Offset(1, 0)
End
With rngSeek.Offset(0, 1)
With .Font
.Name = "Solid Edge ANSI1 Symbols"
.Size = 11
.Value = 1
End With <--added this
End With
'don't need to call Range() around rngSeek - it is already a range type
rngSeek.Offset(0, 3) = "=RC[-1]"
rngSeek.Offset(0, 4) = "0"
With rngSeek.Offset(1, 1)
.Font.Bold = True <--don't really need a With if only one statement
End With
'can use a With statement here if you want:
With rngSeek
.Offset(1, 1) = "X value"
.Offset(2, 1) = "Y Value"
.Offset(0, 4) = "=2*SQRT((R[1]C[-3]-R[1]C)^2+(R[2]C[-3]-R[2]C)^2)"
.Offset(0, 5) = "=2*SQRT((R4C3-R[1]C)^2+(R5C3-R[2]C)^2)"
.Offset(0, 6) = "=2*SQRT((R[1]C[-3]-R[1]C)^2+(R[2]C[-3]-R[2]C)^2)"
.Offset(0, 7) = "=2*SQRT((R[1]C[-3]-R[1]C)^2+(R[2]C[-3]-R[2]C)^2)"
.Offset(0, 8) = "=2*SQRT((R4C3-R[1]C)^2+(R5C3-R[2]C)^2)"
.Offset(0, 2) = (InputBox("Insert Positional Tolerance Diametre"))
.Offset(1, 2) = (InputBox("Insert X value on drawing"))
.Offset(2, 2) = (InputBox("Insert Y value on drawing"))
End With
End Sub