将+1添加到同一行但与Vlooked-up项不同的列中的单元格

时间:2016-01-27 12:35:17

标签: vba excel-vba excel

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

我希望我的代码可以做的是:

  1. 从表格
  2. 上的标签中取出标题
  3. 在工作簿表上查找字母数字标题
  4. 为Vlook部分的同一行但在不同的列上的数字添加+1。

    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
    
  5. 我一直试图让我的头脑这么久,但我总是得到一个“无效的限定符”错误。任何建议都会非常感谢,谢谢!

1 个答案:

答案 0 :(得分:0)

你的passPartNo1workbook是Dim'作为一个字符串;你不能从中获取。我假设你想要找到发现VLookup函数值的行?在这种情况下,您需要.Match函数。