I created (partly copied) a macro that, depending on the selection in the first sheet, adds a row in the first and the second sheet in the same place.
Yesterday morning it all still worked fine, but after doing some testing off all the different functionalities (mostly AutoFilters) it suddenly decided to not use the targeted cell anymore and instead target one at random. It even changes the random cell due to unknown circumstances (yesterday it was one in the first row, then in the 11. etc.).
Im very new to VBA and would be really thankfull for some help with this issue.
Heres my code for adding a row (removing works on the same principle):
Sub Add_Row()
Application.ScreenUpdating = False
ActiveSheet.Unprotect
With ActiveWorkbook.ActiveSheet
If .FilterMode Then
.ShowAllData
End If
End With
Sheets("People to Project").Select
ActiveSheet.Unprotect
With ActiveWorkbook.ActiveSheet
If .FilterMode Then
.ShowAllData
End If
End With
r0w = ActiveCell.Row
c0l = ActiveCell.Column
ThisWorkbook.Sheets("Overview").Cells(r0w, c0l).EntireRow.Insert
ThisWorkbook.Sheets("People to Project").Cells(r0w, c0l).EntireRow.Insert
Sheets("Overview").Select
Range(Cells(r0w, 17), Cells(r0w, 48)).Select
Selection.Style = "1. Projectfield"
Sheets("People to Project").Select
ActiveSheet.Unprotect
Range(Cells(r0w, 12), Cells(r0w, 43)).Select
Selection.Style = "1. Projectfield"
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFiltering:=True
Sheets("Overview").Select
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFiltering:=True
Application.ScreenUpdating = True
End Sub