PC Review


Reply
Thread Tools Rate Thread

how can i make it better (cod to delete rows)

 
 
sheryarkhan
Guest
Posts: n/a
 
      5th Jan 2010
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

 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      5th Jan 2010
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" <(E-Mail Removed)> wrote in message
news:731F5DCF-27EC-4B60-815B-(E-Mail Removed)...
> 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
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofil on variable rows, delete extract and show remaining rows 1plane Microsoft Excel Programming 3 17th Nov 2009 10:49 AM
Hpw do I delete multiple empty rows found between filled rows? Bill Microsoft Excel Worksheet Functions 1 15th Nov 2009 12:52 AM
Copy pasting Rows, but need to Delete any Shapes/Pictures that are within copied rows Corey Microsoft Excel Programming 2 1st Aug 2007 02:02 AM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Microsoft Excel Worksheet Functions 0 13th Dec 2006 01:25 AM
Delete rows with numeric values, leave rows with text =?Utf-8?B?R1NwbGluZQ==?= Microsoft Excel Programming 5 11th Oct 2005 12:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:06 PM.