swaink
Active Member
- Joined
- Feb 15, 2002
- Messages
- 432
Hi All
With the help of Fairwinds I have managed to achieve part of my aim but I would now like to look at this issue to see if I may use VBA to meet my needs.
I have browsed and found some sample code but I'm experiencing some prolems with it. Basically I need to compare Col B with Col E, In Col H I want to show numbers that appear in Col B but not in Col E and also place the corresponding Ref number in Col G.
Having done this I then look at the same Cols and place the Numbers which Appear in Col E but not B and place those details in Cols J & K
This piece of code is failing me in that it is posting values that do appear in both Cols, Would someone please be able to advise me on how I may adjust the code accordingly
Best regards
Kevin
Sub test()
Dim rng1 As Range
Dim rng2 As Range
Dim c As Range
Dim i As Integer
Set rng1 = Range("B3", Range("B3").End(xlDown))
Set rng2 = Range("E3", Range("E3").End(xlDown))
For Each c In rng1
On Error Resume Next
i = WorksheetFunction.Match(c, rng2, 0) + 2
If Err.Number > 0 Then
Range(Cells(i, 1), Cells(i, 2)).Copy _
Range("g65536").End(xlUp).Offset(1, 0)
ActiveCell.Paste
Else
On Error GoTo 0
End If
Next c
End Sub
With the help of Fairwinds I have managed to achieve part of my aim but I would now like to look at this issue to see if I may use VBA to meet my needs.
I have browsed and found some sample code but I'm experiencing some prolems with it. Basically I need to compare Col B with Col E, In Col H I want to show numbers that appear in Col B but not in Col E and also place the corresponding Ref number in Col G.
Having done this I then look at the same Cols and place the Numbers which Appear in Col E but not B and place those details in Cols J & K
This piece of code is failing me in that it is posting values that do appear in both Cols, Would someone please be able to advise me on how I may adjust the code accordingly
Best regards
Kevin
Sub test()
Dim rng1 As Range
Dim rng2 As Range
Dim c As Range
Dim i As Integer
Set rng1 = Range("B3", Range("B3").End(xlDown))
Set rng2 = Range("E3", Range("E3").End(xlDown))
For Each c In rng1
On Error Resume Next
i = WorksheetFunction.Match(c, rng2, 0) + 2
If Err.Number > 0 Then
Range(Cells(i, 1), Cells(i, 2)).Copy _
Range("g65536").End(xlUp).Offset(1, 0)
ActiveCell.Paste
Else
On Error GoTo 0
End If
Next c
End Sub
DHLGMRPT (version 1).xls | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | |||
1 | Sheet1 | Sheet2 | In sheet 1 but not in sheet 2 | ||||||||
2 | Ref no | Item no | Ref no | Item no | |||||||
3 | 7613 | 365471241617 | 7613 | 365471241617 | 7788 | 365471241655 | |||||
4 | 7255 | 365471241624 | 7255 | 365471241624 | 7255 | 365471241624 | |||||
5 | 7260 | 365471241631 | 7260 | 365471241648 | 7788 | 365471241648 | |||||
6 | 7788 | 365471241648 | 7788 | 365471241655 | 7788 | 365471241655 | |||||
7 | 7788 | 365471241655 | 7788 | 365471241679 | |||||||
8 | 7788 | 365471241662 | 7788 | 365471241704 | |||||||
9 | 7613 | 365471241679 | 7613 | 365471241705 | |||||||
10 | 7255 | 365471241686 | 7255 | 365471241706 | |||||||
11 | |||||||||||
12 | |||||||||||
VBA |