Vba 添加+;1到同一行中的单元格,但与已查找项的列不同

Vba 添加+;1到同一行中的单元格,但与已查找项的列不同,vba,excel,Vba,Excel,我对VBA很陌生,所以我为编码错误提前道歉;) 我想让我的代码做的是: 从表单上的标签中获取标题 查找工作簿工作表上的字母数字标题 将+1添加到Vlook部件的同一行但不同列上的数字上 Private Sub submitButton_Click() 'Declaring variables that will be used to Vlookup on the top level part number list Dim passPartNo1form As String Dim passP

我对VBA很陌生,所以我为编码错误提前道歉;)

我想让我的代码做的是:

  • 从表单上的标签中获取标题
  • 查找工作簿工作表上的字母数字标题
  • 将+1添加到Vlook部件的同一行但不同列上的数字上

    Private Sub submitButton_Click()
    'Declaring variables that will be used to Vlookup on the top level part number list
    
    Dim passPartNo1form As String
    Dim passPartNo1workbook As String
    Dim failPartNo1workbook As String
    Dim rowPass1 As Integer
    
    Sheets("Sheet5").Activate
    
    'If Pass checkbox is selected
    If pass1.Value = True Then
    
        'Assign variable passPartNo1form to the caption of the PartNumber1 label
        passPartNo1form = partNumber1.Caption
    
        'Look up the risk score in the Top Level list
        passPartNo1workbook = Application.WorksheetFunction.VLookup(passPartNo1form, Range("TopLevelList"), 3, False)
    
        'This should define the row of the code that has been V looked up
        rowPass1 = passPartNo1workbook.Row
    
        'Add +1 to the number in column 3, and row the same as the part which has been V looked up
        Cells(rowPass1, 3).Value = Cells(2, 3).Value + 1
    
    End If
    
    End Sub
    

  • 多年来,我一直试图解决这个问题,但我总是遇到一个“无效限定符”错误。任何建议都将不胜感激,谢谢

    您的Passpartno1工作簿变暗为字符串;你不能从中吸取教训。我假设您想要得到VLookup函数中的值所在的行?在这种情况下,您需要.Match函数。

    没有比
    Sheet5.Activate更好的功能。您可能需要
    工作表(“Sheet5”)。激活
    。错误上突出显示了哪一行?@EganWolf:不用担心;如果他的工作表中有一张代码名为Sheet5,那么就可以像这样访问它。或者将其保留为字符串并使用工作表(passPartNo1workbook)