|
-
Jun 20th, 2008, 04:42 AM
#1
Thread Starter
Fanatic Member
How to find the difference of DATA
Hello,
I have 3 Excel sheet on which i have 3 Columns each,
1.UserName 2. Name 3. Contact#
I paste some data on Sheet1 in morning and some data on Sheet 2 in evening, How can i got the difference of data on Sheet 3.
Like on sheet 1, I paste only username A, B, C, D, E in morning and A, B, C, D, E, F, G, H, I on Sheet 2 in evening.
How can i get F, G, H, I on sheet 3.
Please help me.
FAROOQ
-
Jun 20th, 2008, 05:25 AM
#2
Re: How to find the difference of DATA
Here is a basic example. you will have to modify this to suit your code.
to understand this, type a-e in Col A in Sheet1 starting from A2 and a-h in Col A in Sheet2 starting from A2. Run this code and it will populate the difference in Sheet3
Code:
Option Explicit
Sub Diff()
Dim Rng1 As Range, Rng2 As Range
Dim cl1 As Range, cl2 As Range
Dim Flg As Boolean
Dim i As Integer
Flg = False
'Change this number to the row
'number from where you want the
'data to be stored in sheet3
'for Example A2
i = 2
'Your range in Sheet1 in Column A in Sheet1
Set Rng1 = Sheets("Sheet1").Range("A2:A6")
'Your range in Sheet1 in Column A in Sheet2
Set Rng2 = Sheets("Sheet2").Range("A2:A9")
For Each cl2 In Rng2
For Each cl1 In Rng1
If cl1.Value = cl2.Value Then
Flg = False
Exit For
Else
Flg = True
End If
Next
'if no match found store value
If Flg = True Then
Sheets("Sheet3").Range("A" & i).Value = cl2.Value
i = i + 1
Flg = False
End If
Next
End Sub
If you have any queries, please feel free to ask.
Hope this puts you in the right direction....
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jun 20th, 2008, 07:21 AM
#3
Re: How to find the difference of DATA
This code works much faster and works with any number of records in Sheet1 and Sheet2.
Code:
Option Explicit
Sub GetNewRecords()
Dim RangeToCopy As Range
Dim UserNameRange As Range
Dim aCell As Range
Set aCell = Sheet2.Range("A2")
Set UserNameRange = Sheet2.Range(aCell, aCell.End(xlDown))
Set RangeToCopy = Sheet2.Range("A1:C1")
For Each aCell In UserNameRange
If Sheet1.Columns(1).Find(What:=aCell, LookAt:=xlWhole) Is Nothing Then
Set RangeToCopy = Union(RangeToCopy, Sheet2.Range(aCell, aCell.Offset(0, 2)))
End If
Next
Sheet3.Cells.ClearContents
RangeToCopy.Copy Sheet3.Range("A1")
End Sub
-
Jun 24th, 2008, 03:10 AM
#4
Thread Starter
Fanatic Member
Re: How to find the difference of DATA
How to use this code in EXCEL ??? I m ery new to Excel
-
Jun 24th, 2008, 04:07 AM
#5
Re: How to find the difference of DATA
In Excel VBA Editor, insert a Module then copy the code above to paste into the new Module.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|