根据现有数据插入评论

我有一个小问题,用我的VBA代码。 我做了一个用户窗体,其中有以下几点:Combobox1是Sku编号Combobox2是testing编号Combobox3是testing结果文本框是Comment_To_Result。

'Inserts comments og test result Dim iRow, iCol With ThisWorkbook.Worksheets("Data sheet") iCol = Application.Match(CLng(ComboBox2.Value), .Columns("Q"), 0) iCol = Application.Match(CLng(ComboBox1.Value), .Columns("A"), 0) ' If IsError(iRow) Then MsgBox "SKU not found": Exit Sub ' If IsError(iCol) Then MsgBox "Test number not found": Exit Sub 'Add test result/next step and comment .Cells(iCol, 30).Value = Me.ComboBox3.Value .Cells(iCol, 30 + 1).Value = Me.Comments_To_Result.Value End With 

我想要代码findsku编号和testing编号,并在此基础上,将testing结果和评论插入同一行。 (SKU和testing编号已经在工作表中)下面的代码工作正常,当testing编号为1,但是当我尝试将testing编号更改为例如2或3时,列代码是debuggen。 有谁知道,有什么可能是错的?

提前致谢!

无论“ Test number列中的search结果如何,您都将结果写入相同的列(30和31)。 你可能想要这个:

 Dim iRow, iCol With ThisWorkbook.Worksheets("Data sheet") iRow = Application.Match(CLng(ComboBox1.Value), .Columns("A"), 0) iCol = Application.Match(CLng(ComboBox2.Value), .Rows(17), 0) If IsError(iRow) Then MsgBox "SKU not found": Exit Sub If IsError(iCol) Then MsgBox "Test number not found": Exit Sub 'Add test result/next step and comment .Cells(iRow, iCol).Value = Me.ComboBox3.Value .Cells(iRow, iCol+1).Value = Me.Comments_To_Result.Value End With 

PS:Sincdesearch的项目是数字(整数),我将组合的值转换为数字,然后在工作表中search它们:

  CLng(ComboBox1.Value) and CLng(ComboBox2.Value) ' ^^^^^ ^^^^^