如何从包含值Id
所有工作表都有Id
行作为位置2nd
。
所以我可以从所有Excel工作表中删除2nd row
吗?
请指导我并给我任何链接?
感谢
下面的代码工作正常但仅适用于打开的工作表。
如何从工作簿中循环显示每个工作表?
Sub demo()
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\ashish.fugat\Desktop\demo.xlsx")
i = 1
Do Until objExcel.Cells(i, 2).Value = ""
If objExcel.Cells(i, 2).Value = "Id" Then
Set objRange = objExcel.Cells(i, 2).EntireRow
objRange.Delete
i = i - 1
End If
i = i + 1
Loop
End Sub
答案 0 :(得分:1)
您可以使用以下方法遍历工作簿中的所有工作表:
Option Explicit
Sub LoopThroughWorksheets()
'declare a worksheet to loop through the workbook with
Dim SheetIdx As Worksheet
For Each SheetIdx In ThisWorkbook.Worksheets
'
'do stuff here
'
'for example, if you wanted to show the name of each sheet
'in the workbook, you could add the following line:
MsgBox (SheetIdx.Name)
Next SheetIdx
End Sub