SOLVED

VBA code to count, copy, paste, last row, if

%3CLINGO-SUB%20id%3D%22lingo-sub-1645649%22%20slang%3D%22en-US%22%3EVBA%20code%20to%20count%2C%20copy%2C%20paste%2C%20last%20row%2C%20if%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1645649%22%20slang%3D%22en-US%22%3E%3CP%3EGood%20evening%3C%2FP%3E%3CP%3EI%20have%20only%20trained%20myself%20in%20excel%20VBA%20and%20have%20been%20able%20to%20learn%20very%20much%20from%20other%20peoples%20questions.%3C%2FP%3E%3CP%3EI%20need%20a%20code%20to%20copy%20the%20data%20in%20image%201%20(Sheet1)%20to%20the%20table%20in%20image%202%20(Sheet2).%3C%2FP%3E%3CP%3EThe%20code%20has%20to%3A%3CBR%20%2F%3E1.%20Count%20the%20amount%20of%20cells%20used%20in%20column%20c%3CBR%20%2F%3E2.%20Copy%20the%20counted%20(in%20step%201)%20amount%20of%20cells%20in%20column%20c%2Cd%20and%20e%3CBR%20%2F%3E3.%20Paste%20in%20last%20row%20%2B1%20in%20sheet2%20in%20column%20c%2Cd%20and%20e%3CBR%20%2F%3E4.%20The%20date%20and%20name%20in%20column%20a%20and%20b%20should%20be%20added%20to%20every%20row%20that%20is%20pasted%3CBR%20%2F%3E5.%20This%20has%20to%20be%20done%20for%20every%20used%20cell%20found%20in%20column%20b%3C%2FP%3E%3CP%3EEnglish%20is%20not%20my%20first%20language.%20Excuse%20me%20if%20the%20explanation%20is%20difficult%20to%20understand.%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1645649%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1646037%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20code%20to%20count%2C%20copy%2C%20paste%2C%20last%20row%2C%20if%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1646037%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F786244%22%20target%3D%22_blank%22%3E%40Kettie%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETry%20this%20macro%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3ESub%20CopyData()%0A%20%20%20%20Dim%20wsh1%20As%20Worksheet%0A%20%20%20%20Dim%20wsh2%20As%20Worksheet%0A%20%20%20%20Dim%20r1%20As%20Long%2C%20r2%20As%20Long%0A%20%20%20%20Dim%20m1%20As%20Long%2C%20m2%20As%20Long%2C%20m3%20As%20Long%2C%20n%20As%20Long%0A%20%20%20%20Application.ScreenUpdating%20%3D%20False%0A%20%20%20%20Set%20wsh1%20%3D%20Worksheets(%22Sheet1%22)%0A%20%20%20%20Set%20wsh2%20%3D%20Worksheets(%22Sheet2%22)%0A%20%20%20%20m1%20%3D%20wsh1.Range(%22A%22%20%26amp%3B%20wsh1.Rows.Count).End(xlUp).Row%0A%20%20%20%20m2%20%3D%20wsh1.Range(%22B%22%20%26amp%3B%20wsh1.Rows.Count).End(xlUp).Row%0A%20%20%20%20m3%20%3D%20wsh1.Range(%22C%22%20%26amp%3B%20wsh1.Rows.Count).End(xlUp).Row%0A%20%20%20%20n%20%3D%20wsh2.Range(%22A%22%20%26amp%3B%20wsh2.Rows.Count).End(xlUp).Row%20%2B%201%0A%20%20%20%20For%20r1%20%3D%202%20To%20m1%0A%20%20%20%20%20%20%20%20For%20r2%20%3D%202%20To%20m2%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22A%22%20%26amp%3B%20n).Resize(m3%20-%201).Value%20%3D%20wsh1.Range(%22A%22%20%26amp%3B%20r1).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22B%22%20%26amp%3B%20n).Resize(m3%20-%201).Value%20%3D%20wsh1.Range(%22B%22%20%26amp%3B%20r2).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22C%22%20%26amp%3B%20n).Resize(m3%20-%201%2C%203).Value%20%3D%20wsh1.Range(%22C2%3AE%22%20%26amp%3B%20m3).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20n%20%3D%20n%20%2B%20m3%20-%201%0A%20%20%20%20%20%20%20%20Next%20r2%0A%20%20%20%20Next%20r1%0A%20%20%20%20Application.ScreenUpdating%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1648744%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20code%20to%20count%2C%20copy%2C%20paste%2C%20last%20row%2C%20if%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1648744%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3BThank%20you%20very%20much%20for%20the%20quick%20reply%20and%20the%20help.%20It%20works%20exactly%20as%20I%20hoped.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWould%20you%20please%20help%20me%20to%20modify%20it%20so%20that%20it%3A%3C%2FP%3E%3CP%3E1.%20Counts%20only%20in%20a%20set%20range%20in%20sheet%201%20i.e%20A8%3AA18%3C%2FP%3E%3CP%3E2.%20Copy%20the%20data%20in%20wsh1%20A2%2C%20B2%2C%20A4%2C%20B4%20to%20wsh2%20column%20G%2CH%2CI%2CJ%3C%2FP%3E%3CP%3E3.%20IF%20wsh1%20column%20G%20is%20in%20g%20%3A%20value%20in%20wsh1%20column%20F%2F1000%20and%20paste%20in%20wsh2%20column%20F.%3C%2FP%3E%3CP%3E4.%20IF%20wsh1%20column%20G%20is%20in%20kg%20%3A%20Copy%20value%20in%20wsh1%20column%20F%20and%20paste%20in%20wsh2%20column%20F.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1649016%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20code%20to%20count%2C%20copy%2C%20paste%2C%20last%20row%2C%20if%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1649016%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F786244%22%20target%3D%22_blank%22%3E%40Kettie%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20is%20a%20new%20version.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3ESub%20CopyData()%0A%20%20%20%20Dim%20wsh1%20As%20Worksheet%0A%20%20%20%20Dim%20wsh2%20As%20Worksheet%0A%20%20%20%20Dim%20r1%20As%20Long%2C%20r2%20As%20Long%0A%20%20%20%20Dim%20m1%20As%20Long%2C%20m2%20As%20Long%2C%20m3%20As%20Long%2C%20n%20As%20Long%0A%20%20%20%20Application.ScreenUpdating%20%3D%20False%0A%20%20%20%20Set%20wsh1%20%3D%20Worksheets(%22Sheet1%22)%0A%20%20%20%20Set%20wsh2%20%3D%20Worksheets(%22Sheet2%22)%0A%20%20%20%20m1%20%3D%20wsh1.Range(%22A19%22).End(xlUp).Row%0A%20%20%20%20m2%20%3D%20wsh1.Range(%22B19%22).End(xlUp).Row%0A%20%20%20%20m3%20%3D%20wsh1.Range(%22C19%22).End(xlUp).Row%20-%207%0A%20%20%20%20n%20%3D%20wsh2.Range(%22A%22%20%26amp%3B%20wsh2.Rows.Count).End(xlUp).Row%20%2B%201%0A%20%20%20%20For%20r1%20%3D%208%20To%20m1%0A%20%20%20%20%20%20%20%20For%20r2%20%3D%208%20To%20m2%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22A%22%20%26amp%3B%20n).Resize(m3).Value%20%3D%20wsh1.Range(%22A%22%20%26amp%3B%20r1).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22B%22%20%26amp%3B%20n).Resize(m3).Value%20%3D%20wsh1.Range(%22B%22%20%26amp%3B%20r2).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22C%22%20%26amp%3B%20n).Resize(m3%2C%203).Value%20%3D%20wsh1.Range(%22C8%3AE%22%20%26amp%3B%20m3%20%2B%207).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20With%20wsh2.Range(%22F%22%20%26amp%3B%20n).Resize(m3)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.Formula%20%3D%20%22%3DSheet1!F8%2FIF(Sheet1!G8%3D%22%22g%22%22%2C1000%2C1)%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.Value%20%3D%20.Value%0A%20%20%20%20%20%20%20%20%20%20%20%20End%20With%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22G%22%20%26amp%3B%20n).Resize(m3%2C%202).Value%20%3D%20wsh1.Range(%22A2%3AB2%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22I%22%20%26amp%3B%20n).Resize(m3%2C%202).Value%20%3D%20wsh1.Range(%22A4%3AB4%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20n%20%3D%20n%20%2B%20m3%0A%20%20%20%20%20%20%20%20Next%20r2%0A%20%20%20%20Next%20r1%0A%20%20%20%20Application.ScreenUpdating%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1664055%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20code%20to%20count%2C%20copy%2C%20paste%2C%20last%20row%2C%20if%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1664055%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGood%20Afternoon%20Hans%3C%2FP%3E%3CP%3EThank%20you%20very%20much%20for%20all%20the%20help.%20The%20previous%20codes%20all%20did%20exactly%20what%20I%20asked.%20I%20did%20however%20simplify%20the%20question%20(for%20privacy%20reasons)%20with%20the%20hope%20of%20modifying%20it%20to%20the%20model%20where%20I%20need%20it%2C%20but%20I%20am%20stuck.%20I%20am%20attaching%20another%20workbook%20with%20the%20exact%20layout%20that%20I%20am%20working%20on.%20Would%20you%20please%20help%20me%20again%3F%3C%2FP%3E%3CP%3ESet%20wsh1%20%3D%20Worksheets(%22Spray%20instruction%20PL%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Set%20wsh2%20%3D%20Worksheets(%22Records.%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3COL%3E%3CLI%3ECount%20the%20amount%20of%20cells%20used%20in%20wsh1%20F16%3AF25%3C%2FLI%3E%3CLI%3ECopy%20the%20counted%20(in%20step%201)%20amount%20of%20cells%20in%20wsh%201%20and%20paste%20in%20in%20last%20row%20%2B1%20wsh2%3A%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CTABLE%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%22301%22%3E%3CP%3ECopy%20wsh1%20column%3A%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22301%22%3E%3CP%3EPaste%20wsh2%20column%3A%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22301%22%3E%3CP%3EF%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22301%22%3E%3CP%3ED%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22301%22%3E%3CP%3EG%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22301%22%3E%3CP%3EE%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22301%22%3E%3CP%3EH%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22301%22%3E%3CP%3EF%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22301%22%3E%3CP%3E%22%3D'Spray%20instruction%20PL'!L16*IF(OR('Spray%20instruction%20PL'!N16%3D%22%22KG%22%22%2C'Spray%20instruction%20PL'!N16%3D%22%22L%22%22)%2C1000%2C1)%2F10%22%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22301%22%3E%3CP%3EG%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22301%22%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20O%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22301%22%3E%3CP%3EI%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22301%22%3E%3CP%3ER%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22301%22%3E%3CP%3EL%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22301%22%3E%3CP%3ET%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22301%22%3E%3CP%3EO%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22301%22%3E%3CP%3EU%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22301%22%3E%3CP%3EA%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3COL%3E%3CLI%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EAlso%20copy%20and%20paste%20the%20value%20of%20the%20following%20cells%20in%20wsh2%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CTABLE%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%22276%22%3E%3CP%3ECopy%20wsh1%20cells%3A%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22277%22%3E%3CP%3EPaste%20wsh2%20column%3A%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22276%22%3E%3CP%3E%24M%2411%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22277%22%3E%3CP%3EM%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22276%22%3E%3CP%3E%22%3DTEXTJOIN(%22%22%20%2C%22%22%2CTRUE%2CK8%2CK7%2CK6)%22%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22277%22%3E%3CP%3EN%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22276%22%3E%3CP%3E%22%3DTEXTJOIN(%22%22%20%2C%22%22%2CTRUE%2CG8%2CG7%2CG6)%22%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22277%22%3E%3CP%3EQ%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22276%22%3E%3CP%3E%24F%245%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22277%22%3E%3CP%3EV%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22276%22%3E%3CP%3E%24O%248%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22277%22%3E%3CP%3EX%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22276%22%3E%3CP%3E%24P%248%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22277%22%3E%3CP%3EY%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3COL%3E%3CLI%3EThe%20data%20in%20step%202%20and%203%20should%20be%20repeated%20for%20every%20used%20cell%20found%20in%20wsh1%20B16%3AB25%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CTABLE%3E%3CTBODY%3E%3CTR%3E%3CTD%20width%3D%22279%22%3E%3CP%3EColumns%20in%20wsh1%20with%20cells%20that%20needs%20to%20repeat%20with%20every%20counted%20row%3A%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22274%22%3E%3CP%3EPaste%20wsh2%20column%3A%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22279%22%3E%3CP%3EB16%3AB25%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22274%22%3E%3CP%3EB%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22279%22%3E%3CP%3EC16%3AC25%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22274%22%3E%3CP%3EC%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22279%22%3E%3CP%3ED16%3AD25%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22274%22%3E%3CP%3EW%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%20width%3D%22279%22%3E%3CP%3EE16%3AE25%3C%2FP%3E%3C%2FTD%3E%3CTD%20width%3D%22274%22%3E%3CP%3EU%3C%2FP%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20look%20forward%20to%20your%20answer.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKind%20regards%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1664212%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20code%20to%20count%2C%20copy%2C%20paste%2C%20last%20row%2C%20if%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1664212%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F786244%22%20target%3D%22_blank%22%3E%40Kettie%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHi%20Kettie%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20think%20this%20will%20do%20it%2C%20but%20please%20test%20thoroughly%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3ESub%20CopyToRecords()%0A%20%20%20%20Dim%20wsh1%20As%20Worksheet%0A%20%20%20%20Dim%20wsh2%20As%20Worksheet%0A%20%20%20%20Dim%20r1%20As%20Long%2C%20r2%20As%20Long%0A%20%20%20%20Dim%20m1%20As%20Long%2C%20m2%20As%20Long%2C%20n%20As%20Long%0A%20%20%20%20Application.ScreenUpdating%20%3D%20False%0A%20%20%20%20Set%20wsh1%20%3D%20Worksheets(%22Spray%20instruction%20PL%22)%0A%20%20%20%20Set%20wsh2%20%3D%20Worksheets(%22Records.%22)%0A%20%20%20%20m1%20%3D%20wsh1.Range(%22B26%22).End(xlUp).Row%0A%20%20%20%20m2%20%3D%20wsh1.Range(%22F26%22).End(xlUp).Row%20-%2015%0A%20%20%20%20n%20%3D%20wsh2.Range(%22A%22%20%26amp%3B%20wsh2.Rows.Count).End(xlUp).Row%20%2B%201%0A%20%20%20%20%20For%20r1%20%3D%2016%20To%20m1%0A%20%20%20%20%20%20%20%20For%20r2%20%3D%2016%20To%20m2%20%2B%2015%0A%20%20%20%20%20%20%20%20%20%20%20%20'%20Based%20on%20column%20B%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22B%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22B%22%20%26amp%3B%20r1).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22C%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22C%22%20%26amp%3B%20r1).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22W%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22D%22%20%26amp%3B%20r1).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22U%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22E%22%20%26amp%3B%20r1).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20'%20Based%20on%20coluumn%20F%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22D%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22F%22%20%26amp%3B%20r2).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22E%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22G%22%20%26amp%3B%20r2).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22F%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22H%22%20%26amp%3B%20r2).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20With%20wsh2.Range(%22G%22%20%26amp%3B%20n).Resize(m2)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.Formula%20%3D%20%22%3D'Spray%20instruction%20PL'!L16*%22%20%26amp%3B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22IF(OR('Spray%20instruction%20PL'!N16%3D%7B%22%22KG%22%22%2C%22%22L%22%22%7D)%2C1000%2C1)%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.Value%20%3D%20.Value%0A%20%20%20%20%20%20%20%20%20%20%20%20End%20With%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22I%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22O%22%20%26amp%3B%20r2).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22L%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22R%22%20%26amp%3B%20r2).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22O%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22T%22%20%26amp%3B%20r2).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22A%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22U%22%20%26amp%3B%20r2).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20'%20Based%20on%20fixed%20cells%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22M%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22M11%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20With%20wsh2.Range(%22N%22%20%26amp%3B%20n).Resize(m2)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.Formula%20%3D%20%22%3DTEXTJOIN(%22%22%2C%22%22%2CTRUE%2C'Spray%20instruction%20PL'!%24K%248%2C%22%20%26amp%3B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22'Spray%20instruction%20PL'!%24K%247%2C'Spray%20instruction%20PL'!%24K%246)%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.Value%20%3D%20.Value%0A%20%20%20%20%20%20%20%20%20%20%20%20End%20With%0A%20%20%20%20%20%20%20%20%20%20%20%20With%20wsh2.Range(%22Q%22%20%26amp%3B%20n).Resize(m2)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.Formula%20%3D%20%22%3DTEXTJOIN(%22%22%2C%22%22%2CTRUE%2C'Spray%20instruction%20PL'!%24G%248%2C%22%20%26amp%3B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22'Spray%20instruction%20PL'!%24G%247%2C'Spray%20instruction%20PL'!%24G%246)%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.Value%20%3D%20.Value%0A%20%20%20%20%20%20%20%20%20%20%20%20End%20With%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22V%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22F5%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22X%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22O8%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20wsh2.Range(%22Y%22%20%26amp%3B%20n).Resize(m2).Value%20%3D%20wsh1.Range(%22P8%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20n%20%3D%20n%20%2B%20m2%0A%20%20%20%20%20%20%20%20Next%20r2%0A%20%20%20%20Next%20r1%0A%20%20%20%20Application.ScreenUpdating%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Good evening

I have only trained myself in excel VBA and have been able to learn very much from other peoples questions.

I need a code to copy the data in image 1 (Sheet1) to the table in image 2 (Sheet2).

The code has to:
1. Count the amount of cells used in column c
2. Copy the counted (in step 1) amount of cells in column c,d and e
3. Paste in last row +1 in sheet2 in column c,d and e
4. The date and name in column a and b should be added to every row that is pasted
5. This has to be done for every used cell found in column b

English is not my first language. Excuse me if the explanation is difficult to understand.

Thanks

 

 

13 Replies
Highlighted
Best Response confirmed by Kettie (Occasional Contributor)
Solution

@Kettie 

Try this macro:

Sub CopyData()
    Dim wsh1 As Worksheet
    Dim wsh2 As Worksheet
    Dim r1 As Long, r2 As Long
    Dim m1 As Long, m2 As Long, m3 As Long, n As Long
    Application.ScreenUpdating = False
    Set wsh1 = Worksheets("Sheet1")
    Set wsh2 = Worksheets("Sheet2")
    m1 = wsh1.Range("A" & wsh1.Rows.Count).End(xlUp).Row
    m2 = wsh1.Range("B" & wsh1.Rows.Count).End(xlUp).Row
    m3 = wsh1.Range("C" & wsh1.Rows.Count).End(xlUp).Row
    n = wsh2.Range("A" & wsh2.Rows.Count).End(xlUp).Row + 1
    For r1 = 2 To m1
        For r2 = 2 To m2
            wsh2.Range("A" & n).Resize(m3 - 1).Value = wsh1.Range("A" & r1).Value
            wsh2.Range("B" & n).Resize(m3 - 1).Value = wsh1.Range("B" & r2).Value
            wsh2.Range("C" & n).Resize(m3 - 1, 3).Value = wsh1.Range("C2:E" & m3).Value
            n = n + m3 - 1
        Next r2
    Next r1
    Application.ScreenUpdating = True
End Sub
Highlighted

@Hans Vogelaar Thank you very much for the quick reply and the help. It works exactly as I hoped. 

 

Would you please help me to modify it so that it:

1. Counts only in a set range in sheet 1 i.e A8:A18

2. Copy the data in wsh1 A2, B2, A4, B4 to wsh2 column G,H,I,J

3. IF wsh1 column G is in g : value in wsh1 column F/1000 and paste in wsh2 column F.

4. IF wsh1 column G is in kg : Copy value in wsh1 column F and paste in wsh2 column F.

 

Thank you 

 

 

Highlighted

@Kettie 

Here is a new version.

Sub CopyData()
    Dim wsh1 As Worksheet
    Dim wsh2 As Worksheet
    Dim r1 As Long, r2 As Long
    Dim m1 As Long, m2 As Long, m3 As Long, n As Long
    Application.ScreenUpdating = False
    Set wsh1 = Worksheets("Sheet1")
    Set wsh2 = Worksheets("Sheet2")
    m1 = wsh1.Range("A19").End(xlUp).Row
    m2 = wsh1.Range("B19").End(xlUp).Row
    m3 = wsh1.Range("C19").End(xlUp).Row - 7
    n = wsh2.Range("A" & wsh2.Rows.Count).End(xlUp).Row + 1
    For r1 = 8 To m1
        For r2 = 8 To m2
            wsh2.Range("A" & n).Resize(m3).Value = wsh1.Range("A" & r1).Value
            wsh2.Range("B" & n).Resize(m3).Value = wsh1.Range("B" & r2).Value
            wsh2.Range("C" & n).Resize(m3, 3).Value = wsh1.Range("C8:E" & m3 + 7).Value
            With wsh2.Range("F" & n).Resize(m3)
                .Formula = "=Sheet1!F8/IF(Sheet1!G8=""g"",1000,1)"
                .Value = .Value
            End With
            wsh2.Range("G" & n).Resize(m3, 2).Value = wsh1.Range("A2:B2").Value
            wsh2.Range("I" & n).Resize(m3, 2).Value = wsh1.Range("A4:B4").Value
            n = n + m3
        Next r2
    Next r1
    Application.ScreenUpdating = True
End Sub
Highlighted

@Hans Vogelaar 

Good Afternoon Hans

Thank you very much for all the help. The previous codes all did exactly what I asked. I did however simplify the question (for privacy reasons) with the hope of modifying it to the model where I need it, but I am stuck. I am attaching another workbook with the exact layout that I am working on. Would you please help me again?

Set wsh1 = Worksheets("Spray instruction PL")

    Set wsh2 = Worksheets("Records.")

 

  1. Count the amount of cells used in wsh1 F16:F25
  2. Copy the counted (in step 1) amount of cells in wsh 1 and paste in in last row +1 wsh2:

 

Copy wsh1 column:

Paste wsh2 column:

F

D

G

E

H

F

"='Spray instruction PL'!L16*IF(OR('Spray instruction PL'!N16=""KG"",'Spray instruction PL'!N16=""L""),1000,1)/10"

G

              O

I

R

L

T

O

U

A

 

  1.  Also copy and paste the value of the following cells in wsh2

 

Copy wsh1 cells:

Paste wsh2 column:

$M$11

M

"=TEXTJOIN("" ,"",TRUE,K8,K7,K6)"

N

"=TEXTJOIN("" ,"",TRUE,G8,G7,G6)"

Q

$F$5

V

$O$8

X

$P$8

Y

 

  1. The data in step 2 and 3 should be repeated for every used cell found in wsh1 B16:B25

 

Columns in wsh1 with cells that needs to repeat with every counted row:

Paste wsh2 column:

B16:B25

B

C16:C25

C

D16:D25

W

E16:E25

U

 

I look forward to your answer.

 

Kind regards

 

Highlighted

@Kettie 

Hi Kettie,

 

I think this will do it, but please test thoroughly:

Sub CopyToRecords()
    Dim wsh1 As Worksheet
    Dim wsh2 As Worksheet
    Dim r1 As Long, r2 As Long
    Dim m1 As Long, m2 As Long, n As Long
    Application.ScreenUpdating = False
    Set wsh1 = Worksheets("Spray instruction PL")
    Set wsh2 = Worksheets("Records.")
    m1 = wsh1.Range("B26").End(xlUp).Row
    m2 = wsh1.Range("F26").End(xlUp).Row - 15
    n = wsh2.Range("A" & wsh2.Rows.Count).End(xlUp).Row + 1
     For r1 = 16 To m1
        For r2 = 16 To m2 + 15
            ' Based on column B
            wsh2.Range("B" & n).Resize(m2).Value = wsh1.Range("B" & r1).Value
            wsh2.Range("C" & n).Resize(m2).Value = wsh1.Range("C" & r1).Value
            wsh2.Range("W" & n).Resize(m2).Value = wsh1.Range("D" & r1).Value
            wsh2.Range("U" & n).Resize(m2).Value = wsh1.Range("E" & r1).Value
            ' Based on coluumn F
            wsh2.Range("D" & n).Resize(m2).Value = wsh1.Range("F" & r2).Value
            wsh2.Range("E" & n).Resize(m2).Value = wsh1.Range("G" & r2).Value
            wsh2.Range("F" & n).Resize(m2).Value = wsh1.Range("H" & r2).Value
            With wsh2.Range("G" & n).Resize(m2)
                .Formula = "='Spray instruction PL'!L16*" & _
                    "IF(OR('Spray instruction PL'!N16={""KG"",""L""}),1000,1)"
                .Value = .Value
            End With
            wsh2.Range("I" & n).Resize(m2).Value = wsh1.Range("O" & r2).Value
            wsh2.Range("L" & n).Resize(m2).Value = wsh1.Range("R" & r2).Value
            wsh2.Range("O" & n).Resize(m2).Value = wsh1.Range("T" & r2).Value
            wsh2.Range("A" & n).Resize(m2).Value = wsh1.Range("U" & r2).Value
            ' Based on fixed cells
            wsh2.Range("M" & n).Resize(m2).Value = wsh1.Range("M11").Value
            With wsh2.Range("N" & n).Resize(m2)
                .Formula = "=TEXTJOIN("","",TRUE,'Spray instruction PL'!$K$8," & _
                    "'Spray instruction PL'!$K$7,'Spray instruction PL'!$K$6)"
                .Value = .Value
            End With
            With wsh2.Range("Q" & n).Resize(m2)
                .Formula = "=TEXTJOIN("","",TRUE,'Spray instruction PL'!$G$8," & _
                    "'Spray instruction PL'!$G$7,'Spray instruction PL'!$G$6)"
                .Value = .Value
            End With
            wsh2.Range("V" & n).Resize(m2).Value = wsh1.Range("F5").Value
            wsh2.Range("X" & n).Resize(m2).Value = wsh1.Range("O8").Value
            wsh2.Range("Y" & n).Resize(m2).Value = wsh1.Range("P8").Value
            n = n + m2
        Next r2
    Next r1
    Application.ScreenUpdating = True
End Sub
Highlighted

Good afternoon @Hans Vogelaar 

 

Thank you for the swift response. It is almost there.

 

There is one thing that you can change for me please. I attached the doc. after I ran the code. There is three lines added for every one that is needed(From the 27 rows the code added, row number 11,15,19;20,24,28;29,33,37 are the exact data I need.). I think instead of trying to explain, I'm going to ask you to have a look at the columns that I highlighted in orange. The red text are data that I posted manually. It is only 9 lines. The code gives 27 lines. Also note that the order of the entries in the green column is not corresponding to the correct info in  WSH 2 Column D to F

 

There was one "/10" that I already added to the IF formula.

 

Thank you so much for all the help.

 

Kind regards

Highlighted

@Kettie 

My apologies, I misunderstood what you wanted. Try this version:

Sub CopyToRecords()
    Dim wsh1 As Worksheet
    Dim wsh2 As Worksheet
    Dim r1 As Long, r2 As Long
    Dim m1 As Long, m2 As Long
    Dim n2 As Long
    Dim n As Long
    Application.ScreenUpdating = False
    Set wsh1 = Worksheets("Spray instruction PL")
    Set wsh2 = Worksheets("Records.")
    m1 = wsh1.Range("A26").End(xlUp).Row
    m2 = wsh1.Range("F26").End(xlUp).Row
    n2 = m2 - 15
    n = wsh2.Range("A" & wsh2.Rows.Count).End(xlUp).Row + 1
    For r1 = 16 To m1
        For r2 = 16 To m2
                wsh2.Range("A" & n).Resize(n2).Value = wsh1.Range("U" & r2).Value
                wsh2.Range("B" & n).Resize(n2).Value = wsh1.Range("B" & r2).Value
                wsh2.Range("C" & n).Resize(n2).Value = wsh1.Range("C" & r2).Value
                wsh2.Range("D" & n).Resize(n2).Value = wsh1.Range("F" & r1).Resize(n2).Value
                wsh2.Range("E" & n).Resize(n2).Value = wsh1.Range("G" & r1).Resize(n2).Value
                wsh2.Range("F" & n).Resize(n2).Value = wsh1.Range("H" & r1).Resize(n2).Value
                With wsh2.Range("G" & n).Resize(n2)
                    .Formula = "='Spray instruction PL'!L16*" & _
                        "IF(OR('Spray instruction PL'!N16={""KG"",""L""}),1000,1)/10"
                    .Value = .Value
                End With
                wsh2.Range("I" & n).Resize(n2).Value = wsh1.Range("O" & r1).Resize(n2).Value
                wsh2.Range("L" & n).Resize(n2).Value = wsh1.Range("R" & r1).Resize(n2).Value
                wsh2.Range("M" & n).Resize(n2).Value = wsh1.Range("M11").Value
                With wsh2.Range("N" & n).Resize(n2)
                    .Formula = "=TEXTJOIN("","",TRUE,'Spray instruction PL'!$K$8," & _
                        "'Spray instruction PL'!$K$7,'Spray instruction PL'!$K$6)"
                    .Value = .Value
                End With
                wsh2.Range("O" & n).Resize(n2).Value = wsh1.Range("T" & r2).Value
                With wsh2.Range("Q" & n).Resize(n2)
                    .Formula = "=TEXTJOIN("","",TRUE,'Spray instruction PL'!$G$8," & _
                        "'Spray instruction PL'!$G$7,'Spray instruction PL'!$G$6)"
                    .Value = .Value
                End With
                wsh2.Range("U" & n).Resize(n2).Value = wsh1.Range("E" & r2).Value
                wsh2.Range("V" & n).Resize(n2).Value = wsh1.Range("F5").Value
                wsh2.Range("W" & n).Resize(n2).Value = wsh1.Range("D" & r2).Value
                wsh2.Range("X" & n).Resize(n2).Value = wsh1.Range("O8").Value
                wsh2.Range("Y" & n).Resize(n2).Value = wsh1.Range("P8").Value
                n = n + n2
        Next r2
    Next r1
    Application.ScreenUpdating = True
End Sub
Highlighted

Thanks again @Hans Vogelaar. I am very close now. Everything goes to the correct place, but I got stuck again. The process gets repeated with the amout of what seems to be the count of column b * count of column f * count of column f (6*4*4=96 entries) only 24 is needed. The entries in red are needed, the rest in black are duplicates.

 

Please advise

Highlighted

@Kettie 

Is this better? (I'm a bit confused by the changes that you applied)

Sub CopyToRecordPL()
    Dim wsh1 As Worksheet
    Dim wsh2 As Worksheet
    Dim r1 As Long, r2 As Long
    Dim m1 As Long, m2 As Long, m3 As Long
    Dim n3 As Long
    Dim n As Long
    Application.ScreenUpdating = False
    Set wsh1 = Worksheets("Spray instruction PL")
    Set wsh2 = Worksheets("Records")
    m1 = wsh1.Range("A26").End(xlUp).Row
    m2 = wsh1.Range("B26").End(xlUp).Row
    m3 = wsh1.Range("F26").End(xlUp).Row
    n3 = m3 - 15
    n = wsh2.Range("A" & wsh2.Rows.Count).End(xlUp).Row + 1
    For r1 = 16 To m1
        For r2 = 16 To m2
                wsh2.Range("A" & n).Resize(n3).Value = wsh1.Range("U" & r2).Value
                wsh2.Range("B" & n).Resize(n3).Value = wsh1.Range("B" & r2).Value
                ' Shouldn't KULTIVAR be copied?
                wsh2.Range("D" & n).Resize(n3).Value = wsh1.Range("F" & r1).Resize(n3).Value
                wsh2.Range("E" & n).Resize(n3).Value = wsh1.Range("G" & r1).Resize(n3).Value
                wsh2.Range("F" & n).Resize(n3).Value = wsh1.Range("H" & r1).Resize(n3).Value
                With wsh2.Range("G" & n).Resize(n3)
                    .Formula = "='Spray instruction PL'!L16*" & _
                        "IF(OR('Spray instruction PL'!N16={""KG"",""L""}),1000,1)/10"
                    .Value = .Value
                End With
                wsh2.Range("I" & n).Resize(n3).Value = wsh1.Range("O" & r1).Resize(n3).Value
                wsh2.Range("L" & n).Resize(n3).Value = wsh1.Range("R" & r1).Resize(n3).Value
                wsh2.Range("M" & n).Resize(n3).Value = wsh1.Range("M11").Value
                With wsh2.Range("N" & n).Resize(n3)
                    .Formula = "=TEXTJOIN("","",TRUE,'Spray instruction PL'!$K$8," & _
                        "'Spray instruction PL'!$K$7,'Spray instruction PL'!$K$6)"
                    .Value = .Value
                End With
                wsh2.Range("O" & n).Resize(n3).Value = wsh1.Range("T" & r2).Value
                With wsh2.Range("Q" & n).Resize(n3)
                    .Formula = "=TEXTJOIN("","",TRUE,'Spray instruction PL'!$G$8," & _
                        "'Spray instruction PL'!$G$7,'Spray instruction PL'!$G$6)"
                    .Value = .Value
                End With
                wsh2.Range("V" & n).Resize(n3).Value = "PL" & wsh1.Range("F5").Value
                wsh2.Range("Y" & n).Resize(n3).Value = wsh1.Range("P8").Value
                ' I don't understand the following - column AB is empty
                ' wsh2.Range("AA" & n).Resize(n3).Value = wsh1.Range("AB" & r1).Resize(n3).Value
                n = n + n3
        Next r2
    Next r1
    Application.ScreenUpdating = True
End Sub
Highlighted

Thank you very much @Hans Vogelaar. It seems that this code does the Job (I made small changes, but are happy with how they worked out). Sorry for the confusion. I worked on the layout of the original and did not apply them to the template. I added them now.

I found another problem that I need help with please. I added a macro called NextsprayinstructionPL(). This needs to be run before copytorecordsPL. The problem that is creates, is that it changes the name and then copytorecordsPL does not apply to it anymore. Is it dangerous to use "active sheet" in "copytorecordsPL" or do you have another plan for me please?

Highlighted

@Kettie 

If you make sure that the sheet you want to use instead of Spray Instructions PL is the active sheet when you run CopyToRecordPL, you can change the line

 

Set wsh1 = Worksheets("Spray instruction PL")

 

in CopyToRecordPL to

 

Set wsh1 = ActiveSheet

Highlighted
Thank you. What can we do regarding the formula in CopytorecordsPL that refers to spray instruction PL?
Highlighted

@Kettie 

Like this:

Sub CopyToRecordPL()
    Dim wsh1 As Worksheet
    Dim wsh2 As Worksheet
    Dim r1 As Long, r2 As Long
    Dim m1 As Long, m2 As Long, m3 As Long
    Dim n3 As Long
    Dim n As Long
    Application.ScreenUpdating = False
    Set wsh1 = ActiveSheet
    Set wsh2 = Worksheets("Records")
    m1 = wsh1.Range("A26").End(xlUp).Row
    m2 = wsh1.Range("B26").End(xlUp).Row
    m3 = wsh1.Range("F26").End(xlUp).Row
    n3 = m3 - 15
    n = wsh2.Range("b" & wsh2.Rows.Count).End(xlUp).Row + 1
    For r1 = 16 To m1
        For r2 = 16 To m2
                wsh2.Range("A" & n).Resize(n3).Value = wsh1.Range("U" & r2).Value
                wsh2.Range("B" & n).Resize(n3).Value = wsh1.Range("B" & r2).Value
                wsh2.Range("AA" & n).Resize(n3).Value = wsh1.Range("AB" & r1).Resize(n3).Value
                wsh2.Range("D" & n).Resize(n3).Value = wsh1.Range("F" & r1).Resize(n3).Value
                wsh2.Range("E" & n).Resize(n3).Value = wsh1.Range("G" & r1).Resize(n3).Value
                wsh2.Range("F" & n).Resize(n3).Value = wsh1.Range("H" & r1).Resize(n3).Value
                With wsh2.Range("G" & n).Resize(n3)
                    .Formula = "='" & wsh1.Name & "'!L16*" & _
                        "IF(OR('" & wsh1.Name & "'!N16={""KG"",""L""}),1000,1)/10"
                    .Value = .Value
                End With
                wsh2.Range("I" & n).Resize(n3).Value = wsh1.Range("O" & r1).Resize(n3).Value
                wsh2.Range("L" & n).Resize(n3).Value = wsh1.Range("R" & r1).Resize(n3).Value
                wsh2.Range("M" & n).Resize(n3).Value = wsh1.Range("M11").Value
                With wsh2.Range("N" & n).Resize(n3)
                    .Formula = "=TEXTJOIN("","",TRUE,'" & wsh1.Name & "'!$K$8," & _
                        "'" & wsh1.Name & "'!$K$7,'" & wsh1.Name & "'!$K$6)"
                    .Value = .Value
                End With
                wsh2.Range("O" & n).Resize(n3).Value = wsh1.Range("T" & r2).Value
                With wsh2.Range("Q" & n).Resize(n3)
                    .Formula = "=TEXTJOIN("","",TRUE,'" & wsh1.Name & "'!$G$8," & _
                        "'" & wsh1.Name & "'!$G$7,'" & wsh1.Name & "'!$G$6)"
                    .Value = .Value
                End With
                wsh2.Range("V" & n).Resize(n3).Value = "PL" & wsh1.Range("F5").Value
                wsh2.Range("Y" & n).Resize(n3).Value = wsh1.Range("P8").Value
                n = n + n3
        Next r2
    Next r1
    Application.ScreenUpdating = True
End Sub