Try this code
Option Explicit
Sub update_sheets()
Dim MySheet As Variant
Dim i As Long, lrow As Long, j As Long
Dim sname As String
Application.ScreenUpdating = False
For Each MySheet In Array("Relevant", "X", "Y", "Z")
With Worksheets(MySheet)
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
If lrow > 1 Then
.Range("A2:O" & lrow).ClearContents
ElseIf lrow = 1 Then
Worksheets("Gross list").Range("A1:O1").Copy .Range("A1")
End If
End With
Next MySheet
With Worksheets("Gross list")
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 2 To lrow
For j = 16 To 19
If .Cells(i, j).Value = "Ja" Then
sname = .Cells(1, j).Value
If j = 16 Then sname = Left(.Cells(1, 16).Value, Len(.Cells(1, 16).Value) - 1)
.Range("A" & i & ":O" & i).Copy Worksheets(sname).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
Next j
Next i
End With
MsgBox "Transfer complete"
Application.ScreenUpdating = True
End Sub
Copy the Excel VBA code
Select the workbook in which you want to store the Excel VBA code
Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
Choose Insert | Module
Where the cursor is flashing, choose Edit | Paste
To run the Excel VBA code:
Choose View | Macros
Select a macro in the list, and click the Run button
Bookmarks