Hello there,
What are you going to use to search for between the workbooks? By your post it seems like you maybe using e-mail addresses. If this is the case what column will the e-mail addresses be in in each workbook?
Below is the code that will hide the rows that do not contains data for you assuming that data appears in column A.
You'll need to change the text in red to your closed workbook's filename.
Sub test()
Dim c As Range
Dim LR As String
Dim B1 As Workbook, B2 As Workbook
Set B1 = ThisWorkbook 'set variable B1 equal to the active workbook
With B1.Sheets(1) 'with the active workbook's first worksheet
HideRows 'run the HideRows macro
End With 'end with this workbook
'change the file path to your workbooks file path
'to get the file path enter into a blank cell =CELL("filename")
'opens other workbook
Application.Workbooks.Open Filename:="C:\Documents and Settings\rvasquez\My Documents\Example Spreadsheets\TestFolder3\Book2.xls"
Set B2 = ActiveWorkbook 'sets B2 to newly opened workbook
With B2.Sheets(1) 'with the first worksheet in B2
HideRows 'run the hiderows macro
End With 'end with the opened workbook
End Sub
Sub HideRows()
Dim LR As String, c As Range
LR = Range("A6555").End(xlUp).Row 'LR is equal to the last row that contains a value in column A
For Each c In Range("A1:A" & LR).Cells 'loop through cells in column A from row 1 to LR
If c.Value = vbNullString Then 'if the current cell in the loop is blank then
c.EntireRow.RowHeight = 0 'hide the row
End If 'end if
Next c 'move to next cell in the loop
End Sub
To insert this code into your workbook
1. Open the workbook that you want to insert the code into and close the other.
2. Press Alt+F11
3. Press Alt, then press i and finally press m (individually not all at the same time)
4. This should add a Module to your project
5. copy and paste the above code into the blank space provided, anything that appears in green is a comment meant to help you understand the code.
6. Close out of Visual Basic
7. Press Alt+F8
8. Select the test macro and then select Run
Bookmarks