我正在尝试为我的代码找到解决方案,首先向用户询问玩家的名字,然后宏在我的数据库中搜索名称。如果名称在那里,那么宏会询问玩家的目标数量。 然后写入inputBox的目标数量将添加到玩家的信息中。
我的问题是宏不会为已搜索的玩家添加目标数。
这是我现在的代码:
Sub goals()
Dim ws As Worksheet
Dim lRow As Long
Dim strSearch As String
Set ws = Worksheets("Data")
Dim etsi As String
etsi = InputBox("Etsi Jäsen", "maalien lisääminen") 'asking the player and finding it
If Trim(etsi) <> "" Then
With Sheets("Data").Range("A:A")
Set Rng = .Find(What:=etsi, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
tulos = InputBox("Anna pelaajan maalienmäärä", "maalien lisääminen")
Range(Rng).Value = "teksti" 'asks the goals and adds them to the player this is my problem area
Else
MsgBox "Jäsentä ei löytynyt"
End If
End With
End If
End Sub
Excel通知我的运行时错误1004。
答案 0 :(得分:1)
变量Rng
已经引用了一个范围对象,因此您不必将其括起来,例如:Range(Rng).Value = "teksti"
。相反,请写Rng.Value = "teksti"
。
当然,上面的代码字面上写着&#34; teksti&#34;进入Rng
指向的单元格。我不确定你想在那里做什么,但如果你不能弄明白,请告诉我们。