Hello everyone.

Can someone modify my code below sheet1 was my payslip form using vlookup and sheet2 as my data base.
Button 2 is to print all payslip of our employees. Now I want to add another data base on sheet3.

Private Sub CommandButton2_Click()
    Dim ws As Worksheet
    Dim LastRow As Long
    Dim Rng As Range

    Set ws = Sheet2

    With ws
        LastRow = .Cells(Rows.Count, "A").End(xlUp).Row

        For Each Rng In .Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible)
            Sheet1.Range("J8") = Rng
            ActiveWindow.SelectedSheets.PrintPreview ' print
        Next
    End With
End Sub
Private Sub Worksheet_Activate()
    Dim ws As Worksheet

    Set ws = Sheet2

    With ws
        LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
    End With

    Sheet1.CommandButton2.Caption = "Print All " & _
        WorksheetFunction.Subtotal(3, Sheet2.Range("A2:A" & LastRow)) & _
        " Records"


    Dim NameAry() As Variant
    Dim A As Long
    With ws
        For A = 2 To LastRow
            ReDim Preserve NameAry(A)
            NameAry(A) = Replace(.Range("D" & A), ",", " - ")
        Next
    End With

    With Sheet1.Range("J8").Validation
        .Delete
        .Add xlValidateList, , , Join(NameAry, ",")
        Application.Calculate
    End With
End Sub