I am new to macros and I am having problems with creating a macro that will copy an entire row from the original worksheet if column B is an LIR to a worksheet labelled LIR and to a worksheet labelled KLE if the row and column B in the original worksheet is KLE. I would like the macro to copy the entire row to the destination worksheet either worksheets LIR and KLE to start at the beginning of the worksheet at row 2 so that when the macro is ran it will updated the worksheets. Currently, when the macro is ran, it keeps adding the rows to the exisiting rows with data and keeps adding to it every time the macro is ran. I am including the the macro below.
Public Sub CopyRows()
LColumn = 1
Sheets("Data").Select
' Find the last row of data
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
' Loop through each row
For x = 2 To FinalRow
' Decide if to copy based on column B
ThisValue = Cells(x, 2).Value
If ThisValue = "LIR" Then
Cells(x, 1).Resize(1, 33).Copy
'Copy to LIR Data1 worksheet
Sheets("LIR").Select
Sheets("LIR").Cells(2, LColumn).PasteSpecial
NextRow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(NextRow, 1).Select
ActiveSheet.Paste
Sheets("Data").Select
ElseIf ThisValue = "KLE" Then
Cells(x, 1).Resize(1, 33).Copy
'Copy to KLE Data1 worksheet
Sheets("KLE").Select
Sheets("KLE").Cells(2, LColumn).PasteSpecial
NextRow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(NextRow, 1).Select
ActiveSheet.Paste
Sheets("Data").Select
End If
Next x
End Sub
Public Sub CopyRows()
LColumn = 1
Sheets("Data").Select
' Find the last row of data
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
' Loop through each row
For x = 2 To FinalRow
' Decide if to copy based on column B
ThisValue = Cells(x, 2).Value
If ThisValue = "LIR" Then
Cells(x, 1).Resize(1, 33).Copy
'Copy to LIR Data1 worksheet
Sheets("LIR").Select
Sheets("LIR").Cells(2, LColumn).PasteSpecial
NextRow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(NextRow, 1).Select
ActiveSheet.Paste
Sheets("Data").Select
ElseIf ThisValue = "KLE" Then
Cells(x, 1).Resize(1, 33).Copy
'Copy to KLE Data1 worksheet
Sheets("KLE").Select
Sheets("KLE").Cells(2, LColumn).PasteSpecial
NextRow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(NextRow, 1).Select
ActiveSheet.Paste
Sheets("Data").Select
End If
Next x
End Sub