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

时间:2017-12-15 00:34:17

标签: excel vba

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

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

1 个答案:

答案 0 :(得分: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

我认为你想做什么