excel中用vba报438错误,高手指点下

来源:百度知道 编辑:UC知道 时间:2024/06/23 18:24:08
Private Sub CommandButton1_Click()
Dim tihao As Integer
tihao = Cells(2, 14) ‘引用一个单元格的数值
Cells(4, 2) = Sheet2!Cells(tihao, 4) ’在一个单元格中动态引用其他单元格内容
End Sub

应该怎么干?

向下面这样就可以了

Private Sub CommandButton1_Click()

Dim tihao As Integer
tihao = Cells(2, 14)
Cells(4, 2) = Sheets("Sheet2").Cells(tihao, 4)

End Sub

是的,我在运行VBA程序时,也出现过此类情况,但是把窗口关闭,再次重新打开,再试,就没有这个问题了

下记是无错的代码。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.EntireRow.Interior.ColorIndex Then
Target.EntireRow.Interior.ColorIndex = 10
Else
Target.EntireRow.Interior.ColorIndex = 0
End If
End Sub