VBA search through rows in spreadsheet

  Kiến thức lập trình

I’m new to VBA. I need to use one spreadsheet to look for data in another one.

Starting with baby steps, I’ve written the code below to step through the rows of column 3 of the first spreadsheet, find the data I’m looking for and print out the row number it’s found on as well as column 13 of that row.

Sub SearchTextInRow()
Dim sheet As Worksheet
ChangedCount = 0
Set sheet = ActiveSheet

For iR = 1 To 100
    If sheet.Cells(iR, 3).Value = "Deleted" Then
        ChangedCount = ChangedCount + 1
        Debug.Print iR
        Debug.Print sheet.Cells(iR, 13).Value
    End If
Next iR

MsgBox ChangedCount

End Sub

The data in column 13 I then want to use to search through a sheet called “Equipment” in another file. So I need to open the 2nd file and do a similar For loop to find what I’m looking for.

Workbooks.Open "C:file1.xlsx"
ActiveSheet.Name = Equipment

This is where I’m getting stuck. How do I reference this new file and sheet to then iterate through it like I had done before ?

1

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT