[英]run-time error '1004' on range selecting
我在此代碼上收到運行時錯誤“ 1004”
sh2是另一個文件上的特定工作表。 我不想激活第二張紙,只需使用它然后關閉文件即可。 我在其他情況下得到我的錯誤
If sh2.Range(sh2.Cells(1, y + 4), sh2.Cells(1, y + 4)) <> "" Then
y = y + 1
Else: sh2.Range(sh2.Cells(1, 4), sh2.Cells(114, (y + 4) - 1)).Select
Selection.Copy
當我嘗試調試時:y為49(必須如此),else下范圍的單元格將獲得自己正確的值。 我的錯誤在哪里?
PS。 我正在使用excel 2013並且在此代碼之前y設置為0
嘗試sh2.Range(sh2.Cells(1, 4), sh2.Cells(114, (y + 4) - 1)).Copy
(不選擇)我認為除非激活它,否則您無法選擇工作表上的任何內容
您的原始代碼對我有用-如果刪除Select
會發生什么?
Dim sh2 As worksheet
Set sh2 = Sheets(2)
y = 49
If sh2.Range(sh2.Cells(1, y + 4), sh2.Cells(1, y + 4)) <> "" Then
y = y + 1
Else
sh2.Range(sh2.Cells(1, 4), sh2.Cells(114, (y + 4) - 1)).Copy
End If
我認為如果您放棄sh2.
從sh2.range
內它將起作用。
將sh2.Range(sh2.Cells(1, y + 4), sh2.Cells(1, y + 4))
更改為
sh2.Range(Cells(1, y + 4), Cells(1, y + 4))
雖然未經測試
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.