Macro solution for Problem 2 ( Problem2b ) - Problem 2 https://excelfox.com/forum/showthrea...ll=1#post14648
This is a conventional solution Problem2b like the ones you have seen a lot of in the last few days. It deletes the rows ( rows 2 and 3 )
Code:' https://excelfox.com/forum/showthread.php/2577-Appendix-Thread-(-Codes-for-other-Threads-(-Avinash-)-)?p=14646&viewfull=1#post14646 ' Problem 2b conventional ' https://excelfox.com/forum/showthread.php/2582-delete-entire-row-by-vbA Sub DeleteRows() Rem 1 Worksheets data info Dim WbABC As Workbook, WsABC As Worksheet Set WbABC = Workbooks.Open(ThisWorkbook.path & "\ABC.xls") Set WsABC = WbABC.Worksheets.Item(1) Dim WbDEF As Workbook, WsDEF As Worksheet Set WbDEF = Workbooks.Open(ThisWorkbook.path & "\DEF PROBLEM 2.xlsx") Set WsDEF = WbABC.Worksheets.Item(1) Dim LrABC As Long, LrDEF As Long Let LrABC = WsABC.Range("A" & WsABC.Rows.Count & "").End(xlUp).Row ' Dynamically getting the last row in worksheet referenced by WsABC Let LrDEF = WsDEF.Range("B" & WsDEF.Rows.Count & "").End(xlUp).Row ' Dynamically getting the last row in worksheet referenced by WsDEF Dim rngSrch As Range Set rngSrch = WsDEF.Range("B1:B" & LrDEF & "") Dim arrDta() As Variant Let arrDta() = WsABC.Range("I1:I" & LrABC & "").Value2 Rem 2 Do it Dim Cnt For Cnt = LrABC To 2 Step -1 Dim MtchedCel As Variant Set MtchedCel = rngSrch.Find(what:=arrDta(Cnt, 1), After:=rngSrch.Item(1), LookIn:=xlValues, LookAt:=xlWhole, SearchDirection:=xlNext, MatchCase:=True) If Not MtchedCel Is Nothing Then ' Range.Find would return nothing if it did not find a match ' If it was Not Nothing then there was a match = condition to delete WsABC.Rows(Cnt).EntireRow.Delete Shift:=xlUp ' The row is deleted , and so we have a space which is filled by shifting all rows in the worksheet Up Else ' MtchedCel is Nothing ' The attempt at a match failed, we got Nothing this is the condition to do nothing End If Next Cnt Rem Close save workbooks WbABC.Close Savechanges:=True ' Save the file and close it WbDEF.Close ' Close file. No changes were made End Sub




Reply With Quote
Bookmarks