|
本帖最后由 yanping11611 于 2016-4-21 19:16 编辑
我想把以下代码中的这一句
If .Range("C1") = 1 Then
Sheets("SHEET13").Select
改成
If .Range("C1") = 1 Then
Sheets("[生产记录.xls]SHEET13").Select
运行就提示“下标越界 9”
我就想改成“选择另外一个叫生产记录.xls的工作薄中的sheet13工作表”。
注明:生产记录.xls的位置和需要修改的文件在同一目录
我完全不懂VBA,麻烦各位大神帮我修改一下!尽管不懂,但能大体猜出里面的道理并以此自己摸索!万分感谢,坐等。
- Sub 提取()
- Dim rngA As Range
- Dim intNum, intRow, intValue As Integer
- With Sheets("sheet2")
- If Sheets("sheet2").Range("c8") = Empty Then
- MsgBox "请输入合同号"
- Else
- Range("c4,c6,g4,g6,g8,m4,m6,m8,p4,p6") = Empty
- KKLL
- intValue = 10
- Set rngA = Range("a:a").Find(.Range("c8"), lookat:=xlWhole)
- If Not rngA Is Nothing Then
- Cells.AutoFilter Field:=4, Criteria1:=Sheets("sheet2").Range("c8")
- .Range("c6") = Cells(rngA.Row, 3)
- .Range("g6") = Cells(rngA.Row, 5)
- .Range("g4") = Cells(rngA.Row, 4)
- .Range("g8") = Cells(rngA.Row, 7)
- .Range("m4") = Cells(rngA.Row, 9)
- .Range("j8") = Cells(rngA.Row, 8)
- .Range("g13") = Cells(rngA.Row, 12)
- .Range("m6") = Cells(rngA.Row, 6)
-
- For intRow = rngA.Row To [d65536].End(xlUp).Row
- For intNum = 4 To 11
- .Cells(intValue, intNum) = Cells(intRow, intNum + 1)
- Next
- intValue = intValue + 1
- Next
- Cells.AutoFilter
- Sheets("sheet2").Select
- MsgBox "记录导出成功"
- Else
- Sheets("sheet2").Select
- MsgBox "找不到此单"
- End If
- End If
- End With
- End Sub
- Sub KKLL()
- With Sheets("SHEET2")
- If .Range("C1") = 1 Then
- Sheets("SHEET13").Select
- Else
- If .Range("C1") = 2 Then
- Sheets("SHEET4").Select
- Else
- If .Range("C1") = 3 Then
- Sheets("SHEET5").Select
- Else
- If .Range("C1") = 4 Then
- Sheets("SHEET6").Select
- Else
- If .Range("C1") = 5 Then
- Sheets("SHEET7").Select
- Else
- If .Range("C1") = 6 Then
- Sheets("SHEET8").Select
- Else
- If .Range("C1") = 7 Then
- Sheets("SHEET9").Select
- Else
- If .Range("C1") = 8 Then
- Sheets("SHEET10").Select
- Else
- If .Range("C1") = 9 Then
- Sheets("SHEET14").Select
- Else
- If .Range("C1") = 10 Then
- Sheets("SHEET15").Select
- Else
- If .Range("C1") = 11 Then
- Sheets("SHEET16").Select
- Else
- If .Range("C1") = 12 Then
- Sheets("SHEET17").Select
- Else
- End If
- End If
- End If
- End If
- End If
- End If
- End If
- End If
- End If
- End If
- End If
- End If
- End With
- End Sub
复制代码
|
|