Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Autofil on variable rows, delete extract and show remaining rows | Excel Programming | |||
Delete & Merge Columns,Delete Rows with filter, etc | Excel Programming | |||
Delete Rows if any cell in Column H is blank but do not Delete Fir | Excel Programming | |||
How to delete rows when List toolbar's "delete" isnt highlighted? | Excel Worksheet Functions | |||
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 | Excel Programming |