Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88054

(Macro)Loop through sheet 1 and sheet 2 for column A if value matches delete the entire row in sheet 1

$
0
0

I have Sheet 1 (Column A ) value and Sheet 2 (Column A). I want to compare sheet 1 column A with sheet 2 Column A. If Sheet 1 (Column A) is found in the Sheet 2 then Delete the entire row in the Sheet 1. go to next one.

I have been stuck on this. Below is my Code. Its not working. Its keep getting wrong cell values

Sub Compare()
Dim i As Long
Dim j As Long
Dim lastRow_Task As Long
Dim lastRow_Compare As Long
Dim lastRow As Long

 'Sheet 1
 Dim Task As Worksheet
'Sheet 2
 Dim Compare As Worksheet

 Set Task = Excel.Worksheets("TaskDetails")
 Set Compare = Excel.Worksheets("Compare")

    Application.ScreenUpdating = False

  lastRow_Task = Log.Cells(Rows.count, "A").End(xlUp).Row

  lastRow_Compare = Compare.Cells(Rows.count, "A").End(xlUp).Row


 For i = 2 To lastRow_Task
     For j = 2 To lastRow_Compare

        If Task.Cells(i, "A").Value = Compare.Cells(j, "A").Value Then
          Compare.Cells(j, "A").ClearContents
       End If
    Next j
Next i

Viewing all articles
Browse latest Browse all 88054

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>