![](/img/trans.png)
[英]Reference to last worksheet in Excel Function to Sum same range across multiple sheets
[英]How to reference same user inputted range across multiple sheets
我正在嘗試刪除工作簿中所有工作表中的所有空行。 我已將以下代碼放在一起,但它似乎只適用於活動工作表。 我正在努力確定為什么它不適用於我的 for 循環的所有工作表。 任何建議表示贊賞
Sub deleteemptyrows()
Dim r As Range, rows As Long, i As Long, ws As Worksheet
Set r = Application.InputBox( _
Title:="Macro Cell Range", _
Prompt:="Select range you would like to delete", _
Type:=8)
On Error GoTo 0
For Each ws In ThisWorkbook.Worksheets
rows = r.rows.Count
For i = rows To 1 Step (-1)
If WorksheetFunction.CountA(r.rows(i)) = 0 Then r.rows(i).Delete
Next
Next ws
End Sub
Sub deleteemptyrows()
Dim ws As Worksheet, rng As Range, strt As Long, stp As Long, i As Long
On Error Resume Next
Set rng = Application.InputBox("Select range you would like to delete", "Macro Cell Range", Type:=8)
strt = rng(1).Row: stp = strt + rng.rows.Count
For Each ws In ThisWorkbook.Worksheets
For i = stp To strt Step (-1)
If WorksheetFunction.CountA(ws.Cells(i, 1).EntireRow) = 0 Then ws.Cells(i, 1).EntireRow.Delete
Next
Next ws
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.