Delete rows based on value in different sheet

%3CLINGO-SUB%20id%3D%22lingo-sub-3475913%22%20slang%3D%22en-US%22%3EDelete%20rows%20based%20on%20value%20in%20different%20sheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3475913%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20would%20I%20reference%20Sheet%20called%20Summary%2C%20cells%20G3%20and%20J3%20below%20so%20that%20it%20deletes%20rows%20with%20dates%20less%20the%20G3%20and%20greater%20than%20J3%3F%20I%20can't%20seem%20to%20get%20it%20to%20look%20up%20the%20date%20in%20these%20cells%20to%20then%20delete%20rows%20from%3F%20And%20is%20it%20possible%20to%20delete%20cells%20based%20on%20time%20and%20date%2C%20for%20example%2C%20if%20cell%20U%20is%20before%20summary%20G3%20AND%20cell%20V%20before%20summary%20G4%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Elr%20%3D%20Cells(Rows.Count%2C%20%22U%22).End(xlUp).Row%20'find%20last%20row%3CBR%20%2F%3EFor%20i%20%3D%20lr%20To%202%20Step%20-1%20'loop%20thru%20backwards%2C%20finish%20at%202%20for%20headers%3CBR%20%2F%3EIf%20Cells(i%2C%20%22U%22).Value%20%26lt%3B%20%3CFONT%20color%3D%22%23DF0000%22%3E%22%3DSummary!G3%22%3C%2FFONT%3E%20Then%20Rows(i).EntireRow.Delete%3CBR%20%2F%3EIf%20Cells(i%2C%20%22U%22).Value%20%26gt%3B%20%3CFONT%20color%3D%22%23DF0000%22%3E%22%3DSummary!J3%22%3C%2FFONT%3E%20Then%20Rows(i).EntireRow.Delete%3CBR%20%2F%3ENext%20i%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3475913%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3475999%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20rows%20based%20on%20value%20in%20different%20sheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3475999%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F874591%22%20target%3D%22_blank%22%3E%40clh_1496%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ESub%20summary()%0A%0ADim%20lr%20As%20Integer%0ADim%20i%20As%20Integer%0A%0Alr%20%3D%20Cells(Rows.Count%2C%20%22U%22).End(xlUp).Row%20'find%20last%20row%0A%0AFor%20i%20%3D%20lr%20To%202%20Step%20-1%20'loop%20thru%20backwards%2C%20finish%20at%202%20for%20headers%0A%0A'column%20%22U%22%20is%20column21%0A%0AIf%20Cells(i%2C%2021).Value%20%26lt%3B%20Worksheets(%22Summary%22).Cells(3%2C%207).Value%20Or%20Cells(i%2C%2021).Value%20%26gt%3B%20Worksheets(%22Summary%22).Cells(3%2C%2010).Value%20Then%0ARows(i).EntireRow.Delete%0A%0AElse%0A%0AEnd%20If%0A%0ANext%20i%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EMaybe%20with%20these%20lines%20of%20code.%20In%20the%20attached%20file%20you%20can%20click%20the%20button%20in%20cell%20R1%20to%20start%20the%20macro.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3481216%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20rows%20based%20on%20value%20in%20different%20sheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3481216%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1174419%22%20target%3D%22_blank%22%3E%40Quadruple_Pawn%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20it%20possible%20to%20add%20an%20AND%20so%20that%20it%20also%20looks%20at%20the%20date%20in%20col%20U%20and%20also%20the%20time%20in%20col%20V%20and%20if%20both%20are%20true%20then%20deletes%20the%20column%3F%20I%20tried%20to%20do%20it%20below%20and%20whilst%20it%20doesn't%20come%20up%20with%20an%20error%2C%20it%20doesn't%20seem%20to%20delete%20anything%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Elr%20%3D%20Cells(Rows.Count%2C%20%22U%22).End(xlUp).Row%20'find%20last%20row%3CBR%20%2F%3Elr%20%3D%20Cells(Rows.Count%2C%20%22V%22).End(xlUp).Row%20'find%20last%20row%3CBR%20%2F%3EFor%20i%20%3D%20lr%20To%202%20Step%20-1%20'loop%20thru%20backwards%2C%20finish%20at%202%20for%20headers%3CBR%20%2F%3E'column%20%22U%22%20is%20column21%3CBR%20%2F%3EIf%20Cells(i%2C%2021).Value%20%26lt%3B%20Worksheets(%22Summary%22).Cells(3%2C%207).Value%20And%20Cells(i%2C%2022).Value%20%26lt%3B%20Worksheets(%22Reference%20Sheet%22).Cells(12%2C%204).Value%20Or%20Cells(i%2C%2021).Value%20%26gt%3B%20Worksheets(%22Reference%20Sheet%22).Cells(4%2C%204).Value%20And%20Cells(i%2C%2022).Value%20%26gt%3B%20Worksheets(%22Reference%20Sheet%22).Cells(13%2C%204).Value%20Then%3CBR%20%2F%3ERows(i).EntireRow.Delete%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3481412%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20rows%20based%20on%20value%20in%20different%20sheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3481412%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F874591%22%20target%3D%22_blank%22%3E%40clh_1496%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ESub%20summaryandreference()%0A%0ADim%20lrU%20As%20Integer%0ADim%20LrV%20As%20Integer%0ADim%20i%20As%20Integer%0A%0AlrU%20%3D%20Cells(Rows.Count%2C%20%22U%22).End(xlUp).Row%20'find%20last%20row%0ALrV%20%3D%20Cells(Rows.Count%2C%20%22V%22).End(xlUp).Row%20'find%20last%20row%0AFor%20i%20%3D%20lrU%20To%202%20Step%20-1%20'loop%20thru%20backwards%2C%20finish%20at%202%20for%20headers%0A'column%20%22U%22%20is%20column21%0AIf%20Cells(i%2C%2021).Value%20%26lt%3B%20Worksheets(%22Summary%22).Cells(3%2C%207).Value%20And%20_%0ACells(i%2C%2022).Value%20%26lt%3B%20Worksheets(%22Reference%20Sheet%22).Cells(12%2C%204).Value%20Or%20_%0ACells(i%2C%2021).Value%20%26gt%3B%20Worksheets(%22Summary%22).Cells(3%2C%2010).Value%20And%20_%0ACells(i%2C%2022).Value%20%26gt%3B%20Worksheets(%22Reference%20Sheet%22).Cells(13%2C%204).Value%20Then%0ARows(i).EntireRow.Delete%0AElse%0AEnd%20If%0ANext%20i%0A%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EMaybe%20with%20this%20code.%20You%20can%20click%20the%20button%20in%20cell%20P1%20in%20the%20attached%20file%20to%20start%20the%20macro.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3504049%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20rows%20based%20on%20value%20in%20different%20sheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3504049%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1174419%22%20target%3D%22_blank%22%3E%40Quadruple_Pawn%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnfortunately%20still%20not%20working%20for%20me%2C%20not%20sure%20if%20it's%20because%20its%20part%20of%20a%20larger%20VBA%20whereby%20I'm%20excluding%3A%3C%2FP%3E%3CPRE%3EDim%20lrU%20As%20Integer%0ADim%20LrV%20As%20Integer%0ADim%20i%20As%20Integer%3C%2FPRE%3E%3CP%3EMy%20whole%20macro%20is%20below%2C%20and%20the%20row%20deleting%20part%20is%20at%20the%20very%20end%20as%20the%20last%20thing%20that%20gets%20done.%20Do%20I%20need%20to%20redim%20lr%20as%20integer%20etc%20to%20get%20this%20to%20work%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESub%20DoAll()%3CBR%20%2F%3EDim%20ws%20As%20Worksheet%3CBR%20%2F%3EDim%20LastRow%20As%20Long%2C%20i%20As%20Long%3CBR%20%2F%3EDim%20tmpArray()%20As%20String%3CBR%20%2F%3EDim%20Formulas()%20As%20Variant%3CBR%20%2F%3E'~~%26gt%3B%20This%20is%20the%20relevant%20sheet%3CBR%20%2F%3ESet%20ws%20%3D%20ThisWorkbook.Sheets(%22Clockings%22)%3CBR%20%2F%3EWith%20ws%3CBR%20%2F%3E'Inserts%20Six%20Columns%20at%20C%2CD%2CE%2CF%2CG%2CH%3CBR%20%2F%3E.Range(%22C%3AH%22).EntireColumn.Insert%3CBR%20%2F%3E.Range(%22C1%22).Formula%20%3D%20%22ID%22%3CBR%20%2F%3E.Range(%22D1%22).Formula%20%3D%20%22Description%22%3CBR%20%2F%3E.Range(%22E1%22).Formula%20%3D%20%22Shift%22%3CBR%20%2F%3E.Range(%22F1%22).Formula%20%3D%20%22Type%22%3CBR%20%2F%3E.Range(%22G1%22).Formula%20%3D%20%22MY%22%3CBR%20%2F%3E.Range(%22H1%22).Formula%20%3D%20%22B%22%3CBR%20%2F%3E.Range(%22V%3AW%22).EntireColumn.Insert%3CBR%20%2F%3E.Range(%22Y%3AZ%22).EntireColumn.Insert%3CBR%20%2F%3E.Range(%22V1%22).Formula%20%3D%20%22Start%20Date%22%3CBR%20%2F%3E.Range(%22W1%22).Formula%20%3D%20%22Start%20Time%22%3CBR%20%2F%3E.Range(%22Y1%22).Formula%20%3D%20%22End%20Date%22%3CBR%20%2F%3E.Range(%22Z1%22).Formula%20%3D%20%22End%20Time%22%3CBR%20%2F%3E'Inserts%20specific%20formulae%20to%20cells%20V2%20and%20W2%3CBR%20%2F%3EReDim%20Formulas(1%20To%202)%3CBR%20%2F%3EFormulas(1)%20%3D%20%22%3DINT(U2)%22%3CBR%20%2F%3EFormulas(2)%20%3D%20%22%3DMOD(U2%2C1)%22%3CBR%20%2F%3E.Range(%22V2%3AW2%22).Formula%20%3D%20Formulas%3CBR%20%2F%3EReDim%20Formulas(1%20To%202)%3CBR%20%2F%3EFormulas(1)%20%3D%20%22%3DIF(X2%3D%22%22%22%22%2C%22%22%22%22%2CINT(X2))%22%3CBR%20%2F%3EFormulas(2)%20%3D%20%22%3DIF(X2%3D%22%22%22%22%2C%22%22%22%22%2CMOD(X2%2C1))%22%3CBR%20%2F%3E.Range(%22Y2%3AZ2%22).Formula%20%3D%20Formulas%3CBR%20%2F%3E'Inserts%20specific%20formulae%20to%20cells%20C2%2CD2.E2.F2.G2%20and%20H2%3CBR%20%2F%3EReDim%20Formulas(1%20To%206)%3CBR%20%2F%3EFormulas(1)%20%3D%20%22%3DIFERROR(VLOOKUP(B2%2C'17%20SO'!A%3AC%2C2%2C0)%2CVLOOKUP(B2%2C'18%20SO'!A%3AC%2C2%2C0))%22%3CBR%20%2F%3EFormulas(2)%20%3D%20%22%3DIFERROR(VLOOKUP(C2%2C'17%20SO'!B%3AD%2C2%2C0)%2CVLOOKUP(C2%2C'18%20SO'!B%3AD%2C2%2C0))%22%3CBR%20%2F%3EFormulas(3)%20%3D%20%22%3DIF(AND(W2%26gt%3B%3D'Reference%20Sheet'!%24C%2414%2CW2%26lt%3B%3D'Reference%20Sheet'!%24C%2412)%2CTEXT(V2-1%2C%22%22ddd%22%22)%26amp%3B%22%22%20%22%22%26amp%3BIF(AND(W2%26gt%3B%3D'Reference%20Sheet'!%24C%2412%2CW2%26lt%3B'Reference%20Sheet'!%24C%2413)%2C'Reference%20Sheet'!%24D%2412%2C'Reference%20Sheet'!%24D%2413)%2CTEXT(V2%2C%22%22ddd%22%22)%26amp%3B%22%22%20%22%22%26amp%3BIF(AND(V2%26gt%3B%3D'Reference%20Sheet'!%24C%2412%2CW2%26lt%3B'Reference%20Sheet'!%24C%2413)%2C'Reference%20Sheet'!%24D%2412%2C'Reference%20Sheet'!%24D%2413))%22%3CBR%20%2F%3EFormulas(4)%20%3D%20%22%3DIF(ISNUMBER(SEARCH(%22%22Sling%22%22%2CD2))%2C%22%22Sling%2FLab%22%22%2CIF(ISNUMBER(SEARCH(%22%22Dress%22%22%2CD2))%2C%22%22NDT%20Dressing%20Support%22%22%2CIF(ISNUMBER(SEARCH(%22%22Downtime%22%22%2CD2))%2C%22%22Downtime%22%22%2CIF(ISNUMBER(SEARCH(%22%22jigs%22%22%2CD2))%2C%22%22Jigs%22%22%2CIF(ISNUMBER(SEARCH(%22%22NC%22%22%2CC2))%2C%22%22NCR%22%22%2CIF(ISNUMBER(SEARCH(%22%22M2%22%22%2CC2))%2C%22%22Change%22%22%2CIF(ISNUMBER(SEARCH(%22%22M3%22%22%2CC2))%2C%22%22Change%22%22%2C%22%22Earning%22%22)))))))%22%3CBR%20%2F%3EFormulas(5)%20%3D%20%22%3DMID(C2%2C4%2C2)%22%3CBR%20%2F%3EFormulas(6)%20%3D%20%22%3DIF(ISNA(VLOOKUP(C2%2C'1811%20SO'!B%3AB%2C1%2CFALSE))%2C%20%22%22III%22%22%2C%20%22%22II%22%22)%22%3CBR%20%2F%3E.Range(%22C2%3AH2%22).Formula%20%3D%20Formulas%3CBR%20%2F%3E'Changes%20number%20format%20in%20Columns%20B%20and%20C%20to%20general%3CBR%20%2F%3E.Range(%22C%3AH%22).NumberFormat%20%3D%20%22General%22%3CBR%20%2F%3ELastRow%20%3D%20Cells.Find(What%3A%3D%22*%22%2C%20SearchOrder%3A%3DxlByRows%2C%20SearchDirection%3A%3DxlPrevious).Row%3CBR%20%2F%3E.Range(%22C2%3AC%22%20%26amp%3B%20LastRow).FillDown%3CBR%20%2F%3E.Range(%22D2%3AD%22%20%26amp%3B%20LastRow).FillDown%3CBR%20%2F%3E.Range(%22E2%3AE%22%20%26amp%3B%20LastRow).FillDown%3CBR%20%2F%3E.Range(%22F2%3AF%22%20%26amp%3B%20LastRow).FillDown%3CBR%20%2F%3E.Range(%22G2%3AG%22%20%26amp%3B%20LastRow).FillDown%3CBR%20%2F%3E.Range(%22H2%3AH%22%20%26amp%3B%20LastRow).FillDown%3CBR%20%2F%3E.Range(%22V2%3AV%22%20%26amp%3B%20LastRow).FillDown%3CBR%20%2F%3E.Range(%22W2%3AW%22%20%26amp%3B%20LastRow).FillDown%3CBR%20%2F%3E.Range(%22Z2%3AZ%22%20%26amp%3B%20LastRow).FillDown%3CBR%20%2F%3E.Range(%22Y2%3Ay%22%20%26amp%3B%20LastRow).FillDown%3CBR%20%2F%3EColumns(%22V%3AW%22).Select%3CBR%20%2F%3ESelection.Copy%3CBR%20%2F%3ESelection.PasteSpecial%20Paste%3A%3DxlPasteValuesAndNumberFormats%2C%20Operation%3A%3D%20_%3CBR%20%2F%3ExlNone%2C%20SkipBlanks%3A%3DFalse%2C%20Transpose%3A%3DFalse%3CBR%20%2F%3EApplication.CutCopyMode%20%3D%20False%3CBR%20%2F%3EColumns(%22Y%3AZ%22).Select%3CBR%20%2F%3ESelection.Copy%3CBR%20%2F%3ESelection.PasteSpecial%20Paste%3A%3DxlPasteValuesAndNumberFormats%2C%20Operation%3A%3D%20_%3CBR%20%2F%3ExlNone%2C%20SkipBlanks%3A%3DFalse%2C%20Transpose%3A%3DFalse%3CBR%20%2F%3EApplication.CutCopyMode%20%3D%20False%3CBR%20%2F%3E'delete%20column%20U%3CBR%20%2F%3E.Range(%22U%3AU%22).EntireColumn.Delete%3CBR%20%2F%3E.Range(%22W%3AW%22).EntireColumn.Delete%3CBR%20%2F%3E.Range(%22AI1%22).Formula%20%3D%20%22Role%22%3CBR%20%2F%3E.Range(%22AJ1%22).Formula%20%3D%20%22Squad%22%3CBR%20%2F%3E'Changes%20number%20format%20in%20Columns%20V%20to%20Time%3CBR%20%2F%3E.Range(%22V%3AV%22).NumberFormat%20%3D%20%22hh%3Amm%22%3CBR%20%2F%3E.Range(%22X%3AX%22).NumberFormat%20%3D%20%22hh%3Amm%22%3CBR%20%2F%3E.Range(%22U%3AU%22).NumberFormat%20%3D%20%22dd%2Fmm%2Fyyyy%22%3CBR%20%2F%3E.Range(%22W%3AW%22).NumberFormat%20%3D%20%22dd%2Fmm%2Fyyyy%22%3CBR%20%2F%3E'Inserts%20specific%20formulae%20to%20cells%20AI2%20and%20AJ2%3CBR%20%2F%3EReDim%20Formulas(1%20To%202)%3CBR%20%2F%3EFormulas(1)%20%3D%20%22%3DVLOOKUP(AG2%2C'Employee%20Info'!A%3AC%2C3%2C0)%22%3CBR%20%2F%3EFormulas(2)%20%3D%20%22%3DVLOOKUP(AH2%2C'Employee%20Info'!B%3AD%2C3%2C0)%22%3CBR%20%2F%3E.Range(%22AI2%3AAJ2%22).Formula%20%3D%20Formulas%3CBR%20%2F%3E'Changes%20number%20format%20in%20Columns%20AI%20and%20AJ%20to%20general%3CBR%20%2F%3E.Range(%22AI%3AAJ%22).NumberFormat%20%3D%20%22General%22%3CBR%20%2F%3ELastRow%20%3D%20Cells.Find(What%3A%3D%22*%22%2C%20SearchOrder%3A%3DxlByRows%2C%20SearchDirection%3A%3DxlPrevious).Row%3CBR%20%2F%3E.Range(%22AI2%3AAI%22%20%26amp%3B%20LastRow).FillDown%3CBR%20%2F%3E.Range(%22AJ2%3AAJ%22%20%26amp%3B%20LastRow).FillDown%3CBR%20%2F%3Elr%20%3D%20Cells(Rows.Count%2C%20%22C%22).End(xlUp).Row%20'find%20last%20row%3CBR%20%2F%3EFor%20i%20%3D%20lr%20To%202%20Step%20-1%20'loop%20thru%20backwards%2C%20finish%20at%202%20for%20headers%3CBR%20%2F%3EIf%20Cells(i%2C%20%22C%22).Text%20%3D%20%22%23N%2FA%22%20Then%20Rows(i).EntireRow.Delete%3CBR%20%2F%3ENext%20i%3CBR%20%2F%3ElrU%20%3D%20Cells(Rows.Count%2C%20%22U%22).End(xlUp).Row%20'find%20last%20row%3CBR%20%2F%3ELrV%20%3D%20Cells(Rows.Count%2C%20%22V%22).End(xlUp).Row%20'find%20last%20row%3CBR%20%2F%3EFor%20i%20%3D%20lrU%20To%202%20Step%20-1%20'loop%20thru%20backwards%2C%20finish%20at%202%20for%20headers%3CBR%20%2F%3E'column%20%22U%22%20is%20column21%3CBR%20%2F%3EIf%20Cells(i%2C%2021).Value%20%26lt%3B%20Worksheets(%22Summary%22).Cells(3%2C%207).Value%20And%20_%3CBR%20%2F%3ECells(i%2C%2022).Value%20%26lt%3B%20Worksheets(%22Reference%20Sheet%22).Cells(12%2C%204).Value%20Or%20_%3CBR%20%2F%3ECells(i%2C%2021).Value%20%26gt%3B%20Worksheets(%22Summary%22).Cells(3%2C%2010).Value%20And%20_%3CBR%20%2F%3ECells(i%2C%2022).Value%20%26gt%3B%20Worksheets(%22Reference%20Sheet%22).Cells(13%2C%204).Value%20Then%3CBR%20%2F%3ERows(i).EntireRow.Delete%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3ENext%20i%3CBR%20%2F%3EEnd%20With%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3505025%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20rows%20based%20on%20value%20in%20different%20sheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3505025%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F874591%22%20target%3D%22_blank%22%3E%40clh_1496%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnfortunately%20i%20can't%20help%20you%20with%20this.%20Maybe%20someone%20else%20can%20help%20you.%20You%20can%20as%20well%20start%20a%20new%20discussion%20with%20your%20question.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

Hi,

 

How would I reference Sheet called Summary, cells G3 and J3 below so that it deletes rows with dates less the G3 and greater than J3? I can't seem to get it to look up the date in these cells to then delete rows from? And is it possible to delete cells based on time and date, for example, if cell U is before summary G3 AND cell V before summary G4?

 

lr = Cells(Rows.Count, "U").End(xlUp).Row 'find last row
For i = lr To 2 Step -1 'loop thru backwards, finish at 2 for headers
If Cells(i, "U").Value < "=Summary!G3" Then Rows(i).EntireRow.Delete
If Cells(i, "U").Value > "=Summary!J3" Then Rows(i).EntireRow.Delete
Next i

5 Replies

@clh_1496 

Sub summary()

Dim lr As Integer
Dim i As Integer

lr = Cells(Rows.Count, "U").End(xlUp).Row 'find last row

For i = lr To 2 Step -1 'loop thru backwards, finish at 2 for headers

'column "U" is column21

If Cells(i, 21).Value < Worksheets("Summary").Cells(3, 7).Value Or Cells(i, 21).Value > Worksheets("Summary").Cells(3, 10).Value Then
Rows(i).EntireRow.Delete

Else

End If

Next i

End Sub

Maybe with these lines of code. In the attached file you can click the button in cell R1 to start the macro.

@Quadruple_Pawn 

 

Is it possible to add an AND so that it also looks at the date in col U and also the time in col V and if both are true then deletes the column? I tried to do it below and whilst it doesn't come up with an error, it doesn't seem to delete anything?

 

lr = Cells(Rows.Count, "U").End(xlUp).Row 'find last row
lr = Cells(Rows.Count, "V").End(xlUp).Row 'find last row
For i = lr To 2 Step -1 'loop thru backwards, finish at 2 for headers
'column "U" is column21
If Cells(i, 21).Value < Worksheets("Summary").Cells(3, 7).Value And Cells(i, 22).Value < Worksheets("Reference Sheet").Cells(12, 4).Value Or Cells(i, 21).Value > Worksheets("Reference Sheet").Cells(4, 4).Value And Cells(i, 22).Value > Worksheets("Reference Sheet").Cells(13, 4).Value Then
Rows(i).EntireRow.Delete

@clh_1496 

Sub summaryandreference()

Dim lrU As Integer
Dim LrV As Integer
Dim i As Integer

lrU = Cells(Rows.Count, "U").End(xlUp).Row 'find last row
LrV = Cells(Rows.Count, "V").End(xlUp).Row 'find last row
For i = lrU To 2 Step -1 'loop thru backwards, finish at 2 for headers
'column "U" is column21
If Cells(i, 21).Value < Worksheets("Summary").Cells(3, 7).Value And _
Cells(i, 22).Value < Worksheets("Reference Sheet").Cells(12, 4).Value Or _
Cells(i, 21).Value > Worksheets("Summary").Cells(3, 10).Value And _
Cells(i, 22).Value > Worksheets("Reference Sheet").Cells(13, 4).Value Then
Rows(i).EntireRow.Delete
Else
End If
Next i


End Sub

Maybe with this code. You can click the button in cell P1 in the attached file to start the macro.

@Quadruple_Pawn 

 

Unfortunately still not working for me, not sure if it's because its part of a larger VBA whereby I'm excluding:

Dim lrU As Integer
Dim LrV As Integer
Dim i As Integer

My whole macro is below, and the row deleting part is at the very end as the last thing that gets done. Do I need to redim lr as integer etc to get this to work?

 

Sub DoAll()
Dim ws As Worksheet
Dim LastRow As Long, i As Long
Dim tmpArray() As String
Dim Formulas() As Variant
'~~> This is the relevant sheet
Set ws = ThisWorkbook.Sheets("Clockings")
With ws
'Inserts Six Columns at C,D,E,F,G,H
.Range("C:H").EntireColumn.Insert
.Range("C1").Formula = "ID"
.Range("D1").Formula = "Description"
.Range("E1").Formula = "Shift"
.Range("F1").Formula = "Type"
.Range("G1").Formula = "MY"
.Range("H1").Formula = "B"
.Range("V:W").EntireColumn.Insert
.Range("Y:Z").EntireColumn.Insert
.Range("V1").Formula = "Start Date"
.Range("W1").Formula = "Start Time"
.Range("Y1").Formula = "End Date"
.Range("Z1").Formula = "End Time"
'Inserts specific formulae to cells V2 and W2
ReDim Formulas(1 To 2)
Formulas(1) = "=INT(U2)"
Formulas(2) = "=MOD(U2,1)"
.Range("V2:W2").Formula = Formulas
ReDim Formulas(1 To 2)
Formulas(1) = "=IF(X2="""","""",INT(X2))"
Formulas(2) = "=IF(X2="""","""",MOD(X2,1))"
.Range("Y2:Z2").Formula = Formulas
'Inserts specific formulae to cells C2,D2.E2.F2.G2 and H2
ReDim Formulas(1 To 6)
Formulas(1) = "=IFERROR(VLOOKUP(B2,'17 SO'!A:C,2,0),VLOOKUP(B2,'18 SO'!A:C,2,0))"
Formulas(2) = "=IFERROR(VLOOKUP(C2,'17 SO'!B:D,2,0),VLOOKUP(C2,'18 SO'!B:D,2,0))"
Formulas(3) = "=IF(AND(W2>='Reference Sheet'!$C$14,W2<='Reference Sheet'!$C$12),TEXT(V2-1,""ddd"")&"" ""&IF(AND(W2>='Reference Sheet'!$C$12,W2<'Reference Sheet'!$C$13),'Reference Sheet'!$D$12,'Reference Sheet'!$D$13),TEXT(V2,""ddd"")&"" ""&IF(AND(V2>='Reference Sheet'!$C$12,W2<'Reference Sheet'!$C$13),'Reference Sheet'!$D$12,'Reference Sheet'!$D$13))"
Formulas(4) = "=IF(ISNUMBER(SEARCH(""Sling"",D2)),""Sling/Lab"",IF(ISNUMBER(SEARCH(""Dress"",D2)),""NDT Dressing Support"",IF(ISNUMBER(SEARCH(""Downtime"",D2)),""Downtime"",IF(ISNUMBER(SEARCH(""jigs"",D2)),""Jigs"",IF(ISNUMBER(SEARCH(""NC"",C2)),""NCR"",IF(ISNUMBER(SEARCH(""M2"",C2)),""Change"",IF(ISNUMBER(SEARCH(""M3"",C2)),""Change"",""Earning"")))))))"
Formulas(5) = "=MID(C2,4,2)"
Formulas(6) = "=IF(ISNA(VLOOKUP(C2,'1811 SO'!B:B,1,FALSE)), ""III"", ""II"")"
.Range("C2:H2").Formula = Formulas
'Changes number format in Columns B and C to general
.Range("C:H").NumberFormat = "General"
LastRow = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Range("C2:C" & LastRow).FillDown
.Range("D2:D" & LastRow).FillDown
.Range("E2:E" & LastRow).FillDown
.Range("F2:F" & LastRow).FillDown
.Range("G2:G" & LastRow).FillDown
.Range("H2:H" & LastRow).FillDown
.Range("V2:V" & LastRow).FillDown
.Range("W2:W" & LastRow).FillDown
.Range("Z2:Z" & LastRow).FillDown
.Range("Y2:y" & LastRow).FillDown
Columns("V:W").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Columns("Y:Z").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'delete column U
.Range("U:U").EntireColumn.Delete
.Range("W:W").EntireColumn.Delete
.Range("AI1").Formula = "Role"
.Range("AJ1").Formula = "Squad"
'Changes number format in Columns V to Time
.Range("V:V").NumberFormat = "hh:mm"
.Range("X:X").NumberFormat = "hh:mm"
.Range("U:U").NumberFormat = "dd/mm/yyyy"
.Range("W:W").NumberFormat = "dd/mm/yyyy"
'Inserts specific formulae to cells AI2 and AJ2
ReDim Formulas(1 To 2)
Formulas(1) = "=VLOOKUP(AG2,'Employee Info'!A:C,3,0)"
Formulas(2) = "=VLOOKUP(AH2,'Employee Info'!B:D,3,0)"
.Range("AI2:AJ2").Formula = Formulas
'Changes number format in Columns AI and AJ to general
.Range("AI:AJ").NumberFormat = "General"
LastRow = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Range("AI2:AI" & LastRow).FillDown
.Range("AJ2:AJ" & LastRow).FillDown
lr = Cells(Rows.Count, "C").End(xlUp).Row 'find last row
For i = lr To 2 Step -1 'loop thru backwards, finish at 2 for headers
If Cells(i, "C").Text = "#N/A" Then Rows(i).EntireRow.Delete
Next i
lrU = Cells(Rows.Count, "U").End(xlUp).Row 'find last row
LrV = Cells(Rows.Count, "V").End(xlUp).Row 'find last row
For i = lrU To 2 Step -1 'loop thru backwards, finish at 2 for headers
'column "U" is column21
If Cells(i, 21).Value < Worksheets("Summary").Cells(3, 7).Value And _
Cells(i, 22).Value < Worksheets("Reference Sheet").Cells(12, 4).Value Or _
Cells(i, 21).Value > Worksheets("Summary").Cells(3, 10).Value And _
Cells(i, 22).Value > Worksheets("Reference Sheet").Cells(13, 4).Value Then
Rows(i).EntireRow.Delete
End If
Next i
End With
End Sub

@clh_1496 

Unfortunately i can't help you with this. Maybe someone else can help you. You can as well start a new discussion with your question.