Sub CopyRow()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim n As Long, lr As Long, lr2 As Long
Application.ScreenUpdating = False
Set sh1 = Sheets("Incidents")
Set sh2 = Sheets("Incidents FR")
n = sh1.ListObjects(1).ListColumns("Situation").Index
sh1.ListObjects(1).Range.AutoFilter Field:=n, Criteria1:="Out of the Rules2"
lr = sh2.Range("B:B").Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row + 1
sh1.AutoFilter.Range.Offset(1).Copy sh2.Range("B" & lr)
lr2 = sh2.Range("B:B").Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
sh2.Range("A" & lr & ":A" & lr2).Value = 1
sh1.ShowAllData
Application.ScreenUpdating = True
End Sub
For future threads, you must enter all the information necessary to provide you with a complete response.1 - my IncidentsFR spreadsheet has a table at the end, and I needed the lines to be copied before this table.
In the events of ThisWorkbook put the following code:2 - how do I make the code run when I open the file?
Private Sub Workbook_Open()
Call CopyRow
End Sub
That's because the file is now macro-enabled.3 - when I saved the file with the code, it appears with an exclamation mark.
Sub CopyRow()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim rng As Range, f As Range, r As Range
Dim i As Long, j As Long, n As Long
Dim newRow As ListRow
Dim cell As String
Application.ScreenUpdating = False
Set sh1 = Sheets("Incidents")
Set sh2 = Sheets("Incidents FR")
n = sh1.ListObjects(1).ListColumns("Situation").Index
Set r = sh1.Columns(n)
Set f = r.Find("Out of the Rules2", , xlValues, xlWhole, , , False)
If Not f Is Nothing Then
cell = f.Address
Do
Set newRow = sh2.ListObjects(1).ListRows.Add
For j = 2 To sh2.Range("B" & Rows.Count).End(3).Row
If sh2.Range("B" & j).Value = "" Then
sh1.Rows(f.Row).Copy sh2.Range("A" & j)
Exit For
End If
Next
Set f = r.FindNext(f)
Loop While f.Address <> cell
End If
Application.ScreenUpdating = True
End Sub
Hi,Try this:....
yes the total line is inside the TableIs that total line inside the table?
In your previous image it was in column B, now it appears in column A.
If you don't put things in from the initial post and continually change them, no macro is going to work.