VBA代码用于将附加信息添加到从用户请求位置的单元

我正在尝试为我的代码find解决scheme,首先向用户询问玩家的名字,然后macros在我的数据库中search名称。 如果名字在那里,那么这个macros会询问玩家有多less个进球。 然后,将写入到input框的目标数添加到玩家的信息中。

我的问题是macros没有添加已经search的玩家的目标数量。

这是我的代码现在:

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。

variablesRng已经指向了一个范围对象,所以你不必把它括起来,例如: Range(Rng).Value = "teksti" 。 相反,写Rng.Value = "teksti"

当然,上面的代码将字面上的单词“teksti”写入到Rng指向的单元格中。 我不确定你想在那里做什么,但让我们知道,如果你无法弄清楚。