View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz[_2_] JLGWhiz[_2_] is offline
external usenet poster
 
Posts: 1,565
Default how can i make it better (cod to delete rows)

Option Explicit
Sub Del()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim i As Long
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet2")
For i = 200 To 1 Step -1
With sh1
If .Cells(i, 1) = sh2.Cells(i, 1) And .Cells(i, 2) = sh2.Cells(i, 2) Then
sh2.Rows(i).Delete
End If
End With
Next
End Sub




"sheryarkhan" wrote in message
...
Hi All!
I'm new to vba.I use this code to delete rows on sheet2 if sheet1 column
"A" has the same data. Can any one help me to make it better


Option Explicit
Dim CellToCheck As Range
Dim CheckValue As String
Dim Cell As Range

Sub del()

For Each CellToCheck In Sheets("Sheet1").Range("A1:A200")
CheckValue = CellToCheck.Value & CellToCheck.Offset(0, 1).Value
For Each Cell In Sheets("Sheet2").Range("A1:A200")
If Cell.Value & Cell.Offset(0, 1).Value = CheckValue Then
Cell.EntireRow.Delete
End If
Next Cell
Next CellToCheck

End Sub

regards