VBA for Excel:Cells(x,y).Value 1004:应用程序定义或对象定义的错误:为什么?

时间:2014-03-28 16:37:46

标签: excel vba excel-vba

我收到1004错误:换行

lstktxt = Cells(lstusefulentry, 12).Value & Cells(lstusefulentry, 13).Value & _
          Cells(lstusefulentry, 14).Value

nextktext = Cells(nextentry, 12).Value & Cells(nextentry, 13).Value & _
            Cells(nextentry, 14).Value
你能想到为什么吗? 感谢

编辑:

感谢您的回复。这是我的完整宏代码。

知道我在哪里介绍错误吗? nextktext和lstktxt被定义为字符串,并且lstusefulentry和nextentry被适当地定义。

Sub processTXT()

'
' processTXT Macro
'

'

Dim last As Integer, lstentry As String, lstusefulentry As Integer, lstktxt As 
String, lastknrextract As Variant, lastknr As Integer, lastkidend As 
Integer, lstrelvntrow As Integer, lastkid As String, kid As String, knr As 
Integer, nextrelvntrow As Integer, nextentry As Integer, nextktext As 
String, nextknrextract As Variant, nextkidend As Integer

last = Range("L" & Rows.Count).End(xlUp).Row
lstentry = Left(Cells(last, 12).Value, 5)
If lstentry = "VOC5B" Then
 lstusefulentry = (last - 16)
 lstrelvntrow = (lstusefulentry + 8)
Else
 MsgBox "Error!"
End If
lstktxt = Cells(lstusefulentry, 12).Value & Cells(lstusefulentry, 13).Value &
Cells(lstusefulentry, 14).Value
lastknrextract = Mid(lstktxt, 12, 3)
If IsNumeric(lastknrextract) Then
    lastknr = CInt(lastknrextract)
Else
    MsgBox "Error!"
End If
lastkidend = InStr(lstktxt, "end")
lastkid = Trim(Mid(lstktxt, 15, (lastkidend - 15)))
knr = lastknr
kid = lastkid
nextrelvntrow = lstrelvntrow
nextentry = lstusefulentry
nextktext = ""

Do While knr >= 1
 Cells(knr + 3, 18).Value = kid
 Cells(knr + 3, 19).Value = Cells(nextrelvntrow, 14).Value
 nextentry = nextentry - 16
 nextrelvntrow = nextentry + 8
 nextktext = Cells(nextentry, 12).Value & Cells(nextentry, 13).Value & 
 Cells(nextentry, 14).Value
nextknrextract = Mid(nextktext, 12, 3)
knr = CInt(nextknrextract)
nextkidend = InStr(nextktext, "end")
kid = Trim(Mid(nextktext, 15, (nextkidend - 15)))
Loop


End Sub

1 个答案:

答案 0 :(得分:0)

lstusefulentry必须是整数变量,其值大于零且小于或等于 Rows.Count