EXCEL中,如何用VBA向单元格赋值?

2024-11-16 19:38:11
推荐回答(3个)
回答1:

sheet1.cells(2,1).value="祝你快乐!",也可以:Worksheets("sheet1").Range("B1").value="祝你快乐!",其中sheet是你所在的表格,sheet1是第一张表

回答2:

ActiveCell.FormulaR1C1 = "祝你快乐!"

你看是这样吗?

回答3:

Sub sss()
Dim myRng As Range
Dim c As Range
Dim myColor As Integer
Dim i As Integer

Dim jg1, jg2, jg3, jg4, jg5 As Integer
Dim 起始行 As Integer
Dim 结束行 As Integer
起始行 = 2 '设置起始行
结束行 = 10 '设置结束行

For i = 起始行 To 结束行 '开始循环计算
Set myRng = Range("o" & i) '赠品1获取价格1
jg1 = Jgjsq(myRng.Value)
Set myRng = Range("P" & i) '赠品2获取价格2
jg2 = Jgjsq(myRng.Value)
Set myRng = Range("Q" & i) '赠品3获取价格3
jg3 = Jgjsq(myRng.Value)
Set myRng = Range("R" & i) '赠品4获取价格4
jg4 = Jgjsq(myRng.Value)
Set myRng = Range("S" & i) '赠品4获取价格4
jg5 = Jgjsq(myRng.Value)
Worksheets("工资核算明细表").Range("U" & i).Value = jg1 + jg2 + jg3 + jg4 + jg5
Next i

End Sub

Function Jgjsq(Zp As String)
Select Case Zp

Case "钢化膜"
jg = 2
Case "保护壳"
jg = 1
Case "全包钢化膜"
jg = 5
Case "耳机"
jg = 3.5
Case "青花瓷碗2件套"
jg = 3.7
Case "平底锅4件套"

Case "电饼铛"
jg = 56
Case "指环扣"
jg = 2.5
Case "钻石玻璃碗6件套"
jg = 14
Case "精品茶具7件套"
jg = 17
Case "九阳电饭煲"
jg = 67
End Select
Jgjsq = jg '返回价格
End Function
已解决