Comparing, deleting and creating a new worksheet

Ed Namzug

New Member
Joined
Mar 21, 2002
Messages
9
Please help in creating a 3rd worksheet which is the result of comparing 1st and 2nd worksheet.
The Sheet 1 has all the original info and consists of columns A & B. The Sheet 2 has new info and also has columns A & B. I would like the macro or program to first look at Sheet 2, compare/delete the data that matches in Sheet 1, list the data that matches only one column then, create
Sheet 3 with the new data. In another way it's like, Sheet 1 - Sheet 2 = Sheet 3
Thanks in advance...:)
 
On 2002-03-29 16:31, Ed Namzug wrote:
Yogi,
You've hit the jackpot.!!! That's exactly my thoughts.., Man..!:)
One Q, please... Where do I type the formula.? On Sheet3 Cell B3? How can I automate it?
I am sorry... Just want to clarify..
All of you Fellas are really awesome and great.!!!
THANK YOU VERY MUCH.!!!

Hi Ed Namzug:
Ya! you enter the formula I suggested in cell B3 of sheet3. Then copy this formula to cells B4, B5, and so on!
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
See, If it helps you..

To run this macro you need to take care that you have two sheets.

Private Sub extractunique()
Dim s1 As Worksheet
Dim s2 As Worksheet
Dim irs1 As Integer
Dim ics1 As Integer
Dim irs2 As Integer
Dim ics2 As Integer
Dim intcomp As Integer
Dim i2 As Integer
Dim i As Integer
Dim sht As Worksheet
Dim flag As Boolean
Dim flag2 As Boolean
Dim inttotalcolumn As Integer

' You need to take care that you have two sheets
Set s1 = Sheet1
Set s2 = Sheet2

For Each sht In Worksheets

If sht.Name = "Extract" Then
flag2 = True
End If
Next sht

If flag2 = False Then
Sheets.Add.Name = "Extract"
End If

'Call clearmarks

Worksheets("Extract").Cells.Clear

irs1 = s1.[a1].CurrentRegion.Rows.Count

ics1 = s1.[a1].CurrentRegion.Columns.Count

irs2 = s2.[a1].CurrentRegion.Rows.Count
ics2 = s2.[a1].CurrentRegion.Columns.Count


If ics1 <> ics2 Then
MsgBox "You Dont Have Equal Columns."
Exit Sub
Else
inttotalcolumn = ics1
End If

For irs1 = 2 To irs1
If irs1 = 4 Then
Debug.Print irs1
End If
flag = True
i2 = 0
For i2 = 2 To irs2
For i = 1 To ics1
If s1.Cells(irs1, i).Value <> s2.Cells(i2, i).Value Then
GoTo label1
End If
If s1.Cells(irs1, i).Value = s2.Cells(i2, i).Value And flag = True Then
intcomp = 1 + intcomp
End If
Next i
i = i - 1
' put the condition according to your columns
' you can have 2 or 3 or 4. Here we have compare
' 11 columns.so intcomp = 11.

If intcomp = inttotalcolumn Then
flag = False
' Worksheets("Extract").Range("a1").SpecialCells(xlCellTypeLastCell).Offset(1, 0).Select
Worksheets("Extract").Select
[a1].Select
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
' Here you need to change the cells(irs1,11) to number of
' column you compare.
s1.Range(Cells(irs1, 1).Address, Cells(irs1, 11).Address).Copy ActiveCell
' if you want to remove the row from the sheet1
's1.Range(Cells(irs1, 1).Address, Cells(irs1, 11).Address).Delete
End If
i = 0
intcomp = 0
s1.Select
label1:
intcomp = 0
Next i2
Next irs1

Worksheets("Extract").Select

End Sub

ni****h desai
http://www.pexcel.com
 
Upvote 0
On 2002-04-01 12:24, thewrenchman wrote:
How do you get a macro to create and/or delete a worksheet?

Hi Thewrenchman

Try turning on your macro recorder and see
what you get.......
If you are not familiar with VBA code then
this is a good technique to use.
If you have problems the post to this site.
Someone will help out.
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,749
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top