Question

How do I remove row from all sheets who is having values Id

all sheets are having Id row as position 2nd.

So I could I remove 2nd row from all excel sheets?

Please guide me and give me any link ?

thanks

below code working good but only for open sheet .

how do I loop through each sheets from workbook ?

 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
Was it helpful?

Solution

You can loop through all worksheets in a workbook using this:

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top