Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default how can i make it better (cod to delete rows)

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofil on variable rows, delete extract and show remaining rows 1plane Excel Programming 2 November 16th 09 09:46 PM
Delete & Merge Columns,Delete Rows with filter, etc traderindia Excel Programming 1 July 16th 09 08:17 PM
Delete Rows if any cell in Column H is blank but do not Delete Fir manfareed Excel Programming 4 September 28th 07 05:20 PM
How to delete rows when List toolbar's "delete" isnt highlighted? Linda Excel Worksheet Functions 1 May 26th 05 08:39 PM
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below Annette[_4_] Excel Programming 2 September 21st 04 02:40 PM


All times are GMT +1. The time now is 10:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"