我認爲這是一個非常簡單的代碼,用於在工作表中的所有活動單元格周圍放置邊界(數據將始終駐留在單元格(1,1)中)。但我得到臭名昭着的「運行時錯誤1004」,我很難過。無法找到運行時錯誤1004
任何幫助,將不勝感激。
Sub test()
Dim myrange As Range
Dim x, y As Integer
x = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
MsgBox x
'------------------------------'
y = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column
MsgBox y
Set myrange = ActiveSheet.Range(Cells(1, 1), Cells(x, y))
With ActiveSheet '<-- erroring here'
.Range(myrange).Select
With Selection.Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
End Sub
@Doug感謝代碼不幸的是其在「與myrange.borders」 – Atwp67
這是更好地使我的回答如下評論拋出一個錯誤 - 這樣我會收到通知。請告訴我錯誤(在我的答案下面)。 –