Sub Macro3()
'
' Macro3 Macro
'
'
Dim ws As Worksheet
Dim rr As Worksheet
On Error Resume Next
Set ws = Worksheets("sheet4")
Set rr = ActiveSheet
If Err Then
Sheets.Add
ActiveSheet.Name = "sheets4"
End If
Dim i As Integer, j As Integer
i = 3
j = 1
Dim r As Integer, c As Integer
Dim st As String
r = 1
rr.Select
With rr.Range("a1:q500")
Set c = Cells.Find("Breaker No.", LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Address
Do
j = 1
st = Cells(Selection.Row - 2, Selection.Column + j).Value
Do
i = 3
c = 2
Cells(Selection.Row, Selection.Column + 1).Copy
Sheets("sheet4").Select
Cells(r, 1).Value = st
Cells(r, c).Paste
rr.Select
c.Select
Do
c = c + 1
Cells(Selection.Row + i, sellection.Column + j).Copy
Sheets("sheet4").Select
Cells(r, c).Paste
rr.Select
c.Select
i = i + 1
Loop While i < 11
j = j + 1
r = r + 1
Loop While j < 13
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstaddress
End If
End With
End Sub
上述代碼中在 Set c = Cells.Find("Breaker No.", LookIn:=xlValues)
這句老是報object require 的錯誤,這是為什么啊
求大神幫忙啊
uj5u.com熱心網友回復:

變數c 的型別不對啊!
Set c = Cells.Find("Breaker No.", LookIn:=xlValues)
執行這句代碼,說明c是屬于“物件”型別的變數,而你之前的變數定義,c As Integer
顯然不能成功執行!
這段代碼,是你錄制宏然后手工修改過的吧!
按你的代碼后面部分,c 又有需要用數值類變數的地方,
你就不能把邏輯理清楚點,再另外定義一個 Object型別或Range型別的變數,用在各自該用的地方???
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/92486.html
標籤:VBA
