Dim c As Range, LR As String, LR1 As String
LR = Sheets(2).Range("A6555").End(xlUp).Row 'set LR equal to the last row in the second tab that contains a value
LR1 = Sheets(1).Range("A6555").End(xlUp).Row 'set LR1 equal to the last row in the first tab that contains a value
With Sheets(2) ' with tab two
For Each c In .Range("A1:A" & LR).Cells 'loop through cells in column A, row 1 through Lr (defined above)
With Sheets(1) 'with the first tab
'set the value in column b of the current cell in the c loop, equal to the number of
'times the value in column A appears in the first tab
c.Offset(0, 1).Value = WorksheetFunction.CountIf(.Range("A1:A" & LR1), c.Value)
End With
Next c ' move to next cell in the loop
End With
You could also achieve the same result by placing the formula in B1 and copying it down to the last row
To insert the macro above into your workbook:
1.Press Alt+F8 on your keyboard
2.Clear the macro name box and type LocateCells in the blank box provided
3.Select the Create option
4.In between the Sub LocateCells() and End Sub copy and paste the above code I have provided. Anything that appears in green is a comment.
5.Exit out of the Visual Basic Window
6.Press Alt+F8 again and this time select the LocateCells macro
7.Select Run
Bookmarks