[英]Using Named Ranges in VBA Excel 2007
I am trying to access a named range from using VBA in Excel 2007. When I used the explicit range ie "A3:M53" I can get the formula below to work. 我试图通过在Excel 2007中使用VBA来访问命名范围。当我使用显式范围(即“ A3:M53”)时,我可以使用以下公式进行工作。 However, when I replace the explicit range with a named range I get an error.
但是,当我用命名范围替换显式范围时,出现错误。 I need to use named ranges as the program needs to select different ranges depending on what data is imported.
我需要使用命名范围,因为程序需要根据导入的数据选择不同的范围。 Fixed.OAX.5 is a named range on the OAX50 worksheet.
Fixed.OAX.5是OAX50工作表上的命名范围。
WorksheetFunction.Match(5, Worksheets("OAX50").Range("Fixed.OAX.5"), 1)
When I run this code I get "Unable to get the Match property of the WorksheetFunction class. 当我运行此代码时,我得到“无法获取WorksheetFunction类的Match属性。
you're most probably not finding value 5
in Worksheets("OAX50").Range("Fixed.OAX.5")
您很可能在
Worksheets("OAX50").Range("Fixed.OAX.5")
找不到值5
use Application.Match()
and wrap any possible error: 使用
Application.Match()
并包装任何可能的错误:
Dim x As Variant
With Worksheets("OAX50").Range("Fixed.OAX.5")
x = Application.Match(5, .Cells, 1)
If IsError(x) Then
MsgBox "Sorry, no match for '5' in range " & .Address & " of worksheet '" & .Parent.Name & "'"
Else
'your code to exploit 'x'
End If
End With
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.