Private Sub Submit_Click()
Application.ScreenUpdating = False
Dim rangeForCode As range, rngLookupRange As range
Dim row As Integer, stock As Integer
Dim result As Integer
Dim drugCodePC As Integer
Dim qty As Integer
Dim ws As Worksheet
drugCodePC = CInt(DrugCode2.Value)
qty = CInt(Quantity.Value)
'Populating the drug name
Set ws = Worksheets("Drug Record")
ws.Select
*Set rangeForCode = ws.range("DrugCodeInventory")*
row = Application.WorksheetFunction.Match(drugCodePC, rangeForCode, 1)
Set rngLookupRange = ws.range("Inventory")
stock = Application.WorksheetFunction.VLookup(drugCodePC, rngLookupRange, 3, False)
result = stock + qty
'MsgBox (row)
ws.Cells(row + 1, 3).Value = result
Application.ScreenUpdating = True
Unload PurchaseForm
End Sub
这会一直抛出错误“对象_worksheet失败的命名范围的方法范围”。 错误发生在**处。我知道这与命名的ranged有关,因为之前,当我编写单元格的范围即。 “A1:A215”起作用。我检查了名称范围,它看起来是正确的。命名范围的名称也是正确的。我试图首先激活工作簿,但错误仍在抛出。
对象_worksheet的方法范围失败,命名范围为
命名的范围是:
= OFFSET(DrugCodeInventory!$A$2, 0, 0, COUNTA(DrugCodeInventory!$A:$A)-1,1)
我只想动态地选择在我的工作表中的第一列。
尝试使用不同的名称作为您的范围(即与表格名称不同) – 2013-03-23 04:15:18
对不起,我有点困惑。你是说范围'DrugCodeInventory'是指'= OFFSET(DrugCodeInventory!$ A $ 2,0,0,COUNTA(DrugCodeInventory!$ A:$ A)-1,1)'? – 2013-03-23 05:22:57
没有答案帮助吗? (如果他们确实把他们+1) - 如果要么意味着你的问题得到解决,那么将其标记为解决方案。 – whytheq 2013-04-01 18:10:28