我正在尝试替换一系列使用“文字”引用的Excel VBA脚本......
Sub OrdenBetel()
'
' OrdenBetel Macro
' Macro recorded 7/14/2006 by
'
Sheets("Master PO CA").Select
Sheets("Master PO CA").Copy After:=Sheets(3)
Sheets("Requerimientos CA").Select
Selection.AutoFilter Field:=1, Criteria1:="Betel International"
Range("C7").Select
Range(Selection, Selection.End(xlDown)).Select
Range("A5:S400").Select
Selection.Copy
Sheets("Master PO CA (2)").Select
Range("A12").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Rows("12:12").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Sheets("Requerimientos CA").Select
Selection.AutoFilter Field:=1
Range("C7").Select
Sheets("Master PO CA (2)").Select
Sheets("Master PO CA (2)").Name = "PO Betel International"
Sheets("PO Betel International").Select
Sheets("PO Betel International").Move
'
End Sub
...使用一个接受字符串参数的VBA脚本:
Dim Vendor_Name As String 'in the General Declarations section
Sub PO_Create(Vendor_Name)
'
'
Sheets("Master PO CA").Select
Sheets("Master PO CA").Copy After:=Sheets(3)
Sheets("Requerimientos CA").Select
Selection.AutoFilter Field:=1, Criteria1:=Vendor_Name
Range("C7").Select
Range(Selection, Selection.End(xlDown)).Select
Range("A5:S400").Select
Selection.Copy
Sheets("Master PO CA (2)").Select
Range("A12").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Rows("12:12").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Sheets("Requerimientos CA").Select
Selection.AutoFilter Field:=1
Range("C7").Select
Sheets("Master PO CA (2)").Select
Sheets(ActiveSheet.Name).Name = Vendor_Name
Sheets(Vendor_Name).Select
Sheets(Vendor_Name).Move
'
End Sub
我正在从Worksheet_Change事件中调用PO_Create:
Private Sub Worksheet_Change(ByVal Target As Range)
If IsEmpty(Target) Then Exit Sub
If Not Intersect(Target, Application.Range("PO_Create_Range")) _
Is Nothing Then
Vendor_Name = ActiveCell.Offset(0, -2).Value
PO_Create (Vendor_Name)
End If
End Sub
...但据我所知,没有任何内容传递给PO_Create。 AutoFilter没有找到任何内容(即使该范围内肯定有值),并且为新的工作表分配了一个通用编号而不是Vendor_Name。