EXCEL VBA 编写程序总是报1004

EXCEL VBA 编写程序总是报1004,第1张

编号为1004的运行时错误的意思是:

不能将=号右边的值赋给等号闭姿埋的左边(一般是一个对象的定义),形如Sheet1.Cells(1, 1) = Sheet2这样的赋值就轿蚂会报册宴1004号错误。

因此问题应出在=号的右边,检查Sheet6.Cells(i + 336, Sheet2.Cells(10, 5).Value)的值。

Private Sub CommandButton1_Click()

Dim arr(7)

For i = 1 To 7

If Int(i / 2) = i / 2 Then

arr(8 - i / 2) = Application.WorksheetFunction.Rept(" ", 4 - i / 2) &i

If i >咐纳 2 Then arr(8 - i / 2) = arr(8 - i / 2) + Application.WorksheetFunction.Rept(" ", Int((i * 2 - 1) / 2) - 2) &i

Else

arr(Int(i / 2) + 1) = Application.WorksheetFunction.Rept("大纯 ", 4 - i / 2) &i

If i >衡仿没 2 Then arr(Int(i / 2) + 1) = arr(Int(i / 2) + 1) + Application.WorksheetFunction.Rept(" ", Int((i * 2 - 1) / 2) - 1) &i

End If

Next

For i = 1 To 7

arr(0) = arr(0) &arr(i) &Chr(10)

Next

MsgBox arr(0)

End Sub

hi,本来想把改动的地方标简拦脊出来,后来发现改动还蛮多的,就不一一标出衡枝了,现在应该可以运行了。

Sub Test()

Dim i As Integer, iRow As Integer

Dim strPath As String

Dim TheSheet As Worksheet

iRow = 1

Set TheSheet = ActiveWorkbook.Worksheets("sheet1")

strPath = ""E:\可丢\hua"拦渗

With Application.FileSearch

.LookIn = strPath

.SearchSubFolders = True

.Filename = "*.*"

If .Execute >0 Then

For i = 1 To .FoundFiles.Count

'Range("A" &i) = .FoundFiles(i)

Workbooks.Open (.FoundFiles(i))

For j = 1 To ActiveWorkbook.Worksheets.Count

'ActiveWorkbook.Worksheets(i).Cells(1, 1).Value = "a"

ActiveWorkbook.Worksheets(j).UsedRange.Copy

TheSheet.Activate

While TheSheet.Range("a" &iRow).Value <>""

iRow = iRow + 1

Wend

TheSheet.Range("A" &iRow).Select

ActiveSheet.Paste

ActiveWorkbook.Save

Next j

Workbooks(Workbooks.Count).Close

Next i

End If

End With

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12270548.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存