案例外部选择案例编译错误

问题描述 投票:0回答:1

我是编码新手,正在寻求帮助。我在这里有一个代码给我“案例外选择案例”错误,但我的情况是在“选择案例”和“结束选择”内,所以我不知道我做错了什么。

Sub codematch()

Dim wbk As Workbook
Select Case response = MsgBox("Is the cursor in the first cell of the column?", vbYesNo, "Code Finder")
Case condition1
    If response = 6 Then
        Set wbk = Workbooks.Open("C:\test.xlsm")
        Call wbk
        ActiveCell.Offset(0, 1).Select
        ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],'[test.xlsm]Sheet1'!C1:C2,2,0)"
        Do Until ActiveCell = ""
        Call wbk.Close(False)
Case condition2
   If response = 7 Then
    response = MsgBox("Position the Cursor in the correct location and try again", vbOKOnly)
   End If
End Select
End Sub
excel vba
1个回答
0
投票

你的大多数代码都是毫无意义的。谁在乎用户拥有光标的位置。

Sub codematch()
dim target as range
set target = range("B1") 'or whever you want to start
Dim wbk As Workbook
Set wbk = Workbooks.Open("C:\test.xlsm")
Target.FormulaR1C1 = "=VLOOKUP(RC[-1],'[test.xlsm]Sheet1'!C1:C2,2,0)"

do 
   set target = target.offset(1,0)
   target.offset(-1,0).copy target
loop until target.offset(0,-1)=""
target.clear
target.parent.columns(target.column).cells.formula = 
_target.parent.columns(target.column).cells.value 'convert to values
wbk.close false
end sub

是我认为你想要做的

© www.soinside.com 2019 - 2024. All rights reserved.