【发布时间】:2014-08-26 22:04:49
【问题描述】:
如果相关的水费和电费账单延迟一个月或更长时间,我正在尝试让此代码粘贴房屋 #。我有这个完全相同的代码在同一个工作簿(尽管不同的工作表)中使用另一组类似的数据运行得非常好,但是我在指示的行上得到“Run.time error '1004': Application-defined or object-defined error”当我运行它时。为什么这段代码在这些情况下不起作用?
'General Variables
Dim myDate As Integer
Dim getDate As String
Dim colPaste As String
Dim colPensionNumb As String
Dim colPaste3 As String
Dim colPaste2 As String
Dim colCelular As String
Dim colPaste4 As String
Dim colPaste5 As String
'Agua Variables
Dim aguaNumb As Integer
Dim aguaNumb2 As Integer
Dim colNameAgua As String
Dim colPasteA As String
'Luz Variables
Dim luzNumb As Integer
Dim luzNumb2 As Integer
Dim colNameLuz As String
Dim colPasteL As String
'General Values
colPaste = "A"
colCelular = "G"
colPensionNumb = "H"
myDate = Month(Date)
colPaste3 = "E"
colPaste4 = "F"
colPaste5 = "G"
'Agua Values
colNameAgua = "C"
colPasteA = "B"
'Luz Values
colNameLuz = "D"
colPasteL = "C"
'Agua
For aguaNumb = 3 To 5
If Month(Worksheets("Proxima Lectura").Range(colNameAgua & aguaNumb).Value) < myDate - 1 Then
' ---------THE FOLLOWING LINE IS WHERE THE ERROR OCCURS------------
Worksheets("Title Page").Range(colPasteA & aguaNumb).Value = Worksheets("Proxima Lectura").Range(colNameAgua & aguaNumb).Value
End If
Next aguaNumb
编辑
现在代码没有给我错误,但它没有给我 IF 语句中的行的任何结果
【问题讨论】:
-
您使用的是什么版本的 Excel?
-
我使用的是 Excel 2013
-
我对那段代码没有任何错误。它必须是其他东西,无论是在您的工作表中,还是在另一本书中等。没有更多细节/屏幕截图等,很难/不可能说。
-
除非我有 10 个代表点,否则 Stackoverflow 不会让我发布图片......但是,我添加了一些消息框,似乎我需要工作的行被跳过了。它绝对没有给我任何结果(a.k.a. 它不会改变任何它应该改变的信息)
-
你能进入“Proxima Lectura”表中的单元格C3、C4、C5吗?进入单元格(通过双击)并复制列标签上方文本框中显示的所有内容?我预计这是某种日期,但需要确切了解您在这些单元格中的内容。
标签: excel excel-2013 vba