我有一个代码可以检查Excel文件的存储路径,并根据提供的输入将其保存到其他位置。我添加了一个Vlookup函数,该函数可以正常工作以获取输入。但是,当我使用case语句时,即使满足该值,控件也只会跳过所有情况。
Private Sub CommandButton6_Click()
Dim strName As String
Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
Dim StrPath As String
Dim myFirstColumn As Long
Dim myLastColumn As Long
Dim myColumnIndex As Long
Dim myFirstRow As Long
Dim myLastRow As Long
Dim SaveLocation As String
Dim myTableArray As Range
myLookupValue = wsA.Range("B2").Value
myFirstColumn = 2
myLastColumn = 8
myColumnIndex = 7
myFirstRow = 19
myLastRow = 78
With Worksheets("List")
Set myTableArray = .Range(.Cells(myFirstRow, myFirstColumn),
.Cells(myLastRow, myLastColumn))
End With
myVlookupResult = WorksheetFunction.VLookup(myLookupValue, myTableArray,
myColumnIndex, False)
strName = wsA.Range("B5").Value
Worksheets("Sheet1").Unprotect Password:=123456
wsA.Range("A6").Clear ' new line for date and time
wsA.Range("A6").Value = wsA.Range("G5").Value ' new line for date and time
Range("A6").Select
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
If ActiveSheet.CheckBoxes.Count > 0 Then
ActiveSheet.CheckBoxes.Visible = True
ActiveSheet.CheckBoxes.Enabled = False
End If
Worksheets("Sheet1").Protect Password:=123456
SaveLocation = myVlookupResult
Select Case SaveLocation
Case "MCT"
StrPath = "MCT Gates"
Case "BG"
StrPath = "Secondary Screening Gates"
End Select
ActiveWorkbook.SaveAs
Filename:= StrPath & "/For Approval/" & strName & ".xlsm" _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Worksheets("Sheet1").Protect Password:=123456
End Sub