Hello! I am new to VBA as you will probably be able to tell. I have read a lot on this forum and I am having a great time learning!
My problem:
I need to copy rows of data from the master sheet(sheet4) and insert into other sheets depending on the data in column A. The below code does everything correctly except it paste the rows instead of inserting them which overwrites my subtotaling data at the bottom. If it helps I can insert/paste the copied rows into row 8 in all other sheets as they are all the exact same with exception to the master sheet.
OR...would I be better off making my tech sheets section for pasting longer than then i expected the pasted data to be and have a code to delete unused rows?
I really hope this is understandable as I am horrible at explaining things. lol
The code I was trying:
Sub Master_to_tech()
'872006
Dim lastrow As Long, lastcol As Long, nextrow As Long
Dim rng As Range
Application.ScreenUpdating = False
nextrow = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row + 1
With Sheet4
lastrow = .Cells(Rows.Count, "F").End(xlUp).Row
lastcol = .Cells(1, Columns.Count).End(xlToLeft).Column
.AutoFilterMode = False
Set rng = .Range("A1", .Cells(lastrow, lastcol))
rng.AutoFilter field:=1, Criteria1:="DVOK872006"
rng.Offset(1, 0).SpecialCells(12).Copy Sheet2.Range("A" & nextrow)
rng.Offset(1, 0).EntireRow.Delete Shift:=xlUp
.AutoFilterMode = False
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
Set rng = Nothing
'872008
Application.ScreenUpdating = False
nextrow = Sheet3.Cells(Rows.Count, "A").End(xlUp).Row + 1
With Sheet4
lastrow = .Cells(Rows.Count, "F").End(xlUp).Row
lastcol = .Cells(1, Columns.Count).End(xlToLeft).Column
.AutoFilterMode = False
Set rng = .Range("A1", .Cells(lastrow, lastcol))
rng.AutoFilter field:=1, Criteria1:="DVOK872008"
rng.Offset(1, 0).SpecialCells(12).Copy Sheet3.Range("A" & nextrow)
rng.Offset(1, 0).EntireRow.Delete Shift:=xlUp
.AutoFilterMode = False
End With
End Sub
I have attached a very short version of my workbook(as in the end it will have over 40 sheets) and what I need the end result to be. Thanks so much in advance!
after code.xlsmbefore code.xlsm
Bookmarks