Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help on deleting rows using Macros

I have two workbooks in the following fashion:

Workbook1/Sheet1 Workbook2/Sheet1
aaa aaa
bbb bbb
ccc
ddd
eee

I want the macro to delete the values in Workbook1/Sheet1/Col1 if they match
with the values ith Workbook2/Sheet1/Col1.

Thanks for your help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Help on deleting rows using Macros

havn't tested this thouroughly but it should work:

Sub Delete_If_Match()
Dim firstRow As Integer, lastRow As Integer
Dim firstRow2 As Integer, lastRow2 As Integer

'WB1 range
firstRow = 1
lastRow = 8

'WB2 range
firstRow2 = 1
lastRow2 = 3

For i = firstRow To lastRow
For j = firstRow2 To lastRow2
If Workbooks("WB1.xls").Worksheets("Sheet1").Cells(i,
1).Value = Workbooks("WB2.xls").Worksheets("Sheet1").Cells(j, 1).Value
Then
Workbooks("WB1.xls").Worksheets("Sheet1").Cells(i,
1).EntireRow.delete
i = i - 1
Exit For
End If
Next j
Next i
End Sub

ashel wrote:
I have two workbooks in the following fashion:

Workbook1/Sheet1 Workbook2/Sheet1
aaa aaa
bbb bbb
ccc
ddd
eee

I want the macro to delete the values in Workbook1/Sheet1/Col1 if they match
with the values ith Workbook2/Sheet1/Col1.

Thanks for your help.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Help on deleting rows using Macros

Hi, do you know how to coding using VBA? I solution will use a lot of hand
coding. This is just a rough overview of that I would do.

For some tips:
Record a "Find" operation by column and modify it to take string value.
Use a Range object to memorize the current selected cell in WB2.
use a loop like this
Workbooks("WB2").Sheets("sheet1").RangeObject.sele ct
do until RangeObject.FormulaC1R1 = ""
searchValue = RangeObject.FormulaC1R1
Workbooks("WB1").Sheets("sheet1").Range("A1").sele ct
while Fine(searchValue) = true then Rows(cstr(activecell.row)
+""+cstr(activecell.row)).delete
Workbooks("WB2").Sheets("sheet1").RangeObject.sele ct
RangeObject.row = RangeObject.row +1
loop




"ashel" wrote:

I have two workbooks in the following fashion:

Workbook1/Sheet1 Workbook2/Sheet1
aaa aaa
bbb bbb
ccc
ddd
eee

I want the macro to delete the values in Workbook1/Sheet1/Col1 if they match
with the values ith Workbook2/Sheet1/Col1.

Thanks for your help.

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
macros deleting rows Anthony Excel Discussion (Misc queries) 1 July 19th 09 12:54 PM
Deleting Macros T Fuller Excel Discussion (Misc queries) 1 January 13th 06 10:03 PM
Deleting Rows using Macros bernard Excel Discussion (Misc queries) 3 August 8th 05 04:52 PM
Converting formula to value and deleting rows using macros. Pank Excel Discussion (Misc queries) 4 July 15th 05 09:58 AM
Deleting Macros Steve Excel Programming 0 November 17th 03 05:27 PM


All times are GMT +1. The time now is 09:51 AM.

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"