Hi all,
I'm new to VBA and i'm really stuck. Any help is much appreciated.
I'm trying to compare two columns in 2 separate files and split one of them into two files.
"Trained" is a worksheet of all those trained in a procedure (both historical and currently employed).
"Employed" is a worksheet of all those currently employed in the company (trained & not trained).
I want to to end up with a worksheet "current and trained", and another called "historical and trained".
I can compare "Employed" with "Trained".
My logic is:
if name from "Employed" is in "Trained" leave it there (this will be renamed my "current and trained" file).
else move to "historical and trained" (already created)
I'm having difficulty with the If else statements. My compare sub is below. Any help would be great.
Sub CompareDel()
Dim Range1 As Range, Range2 As Range, rng1 As Range, rng2 As Range, outRng As Range
Set Range1 = Application.Selection
Set Range1 = Application.InputBox("Range1 :", Type:=8)
Set Range2 = Application.InputBox("Range2:", Type:=8)
Application.ScreenUpdating = False
For Each rng1 In Range1
xValue = rng1.Value
For Each rng2 In Range2
If xValue = rng2.Value Then
If outRng Is Nothing Then
Set outRng = rng1
Else
Set outRng = Application.Union(outRng, rng1)
End If
End If
Next
Next
'I think the If statements should go here but i'm not sure
End Sub
I'm new to VBA and i'm really stuck. Any help is much appreciated.
I'm trying to compare two columns in 2 separate files and split one of them into two files.
"Trained" is a worksheet of all those trained in a procedure (both historical and currently employed).
"Employed" is a worksheet of all those currently employed in the company (trained & not trained).
I want to to end up with a worksheet "current and trained", and another called "historical and trained".
I can compare "Employed" with "Trained".
My logic is:
if name from "Employed" is in "Trained" leave it there (this will be renamed my "current and trained" file).
else move to "historical and trained" (already created)
I'm having difficulty with the If else statements. My compare sub is below. Any help would be great.
Sub CompareDel()
Dim Range1 As Range, Range2 As Range, rng1 As Range, rng2 As Range, outRng As Range
Set Range1 = Application.Selection
Set Range1 = Application.InputBox("Range1 :", Type:=8)
Set Range2 = Application.InputBox("Range2:", Type:=8)
Application.ScreenUpdating = False
For Each rng1 In Range1
xValue = rng1.Value
For Each rng2 In Range2
If xValue = rng2.Value Then
If outRng Is Nothing Then
Set outRng = rng1
Else
Set outRng = Application.Union(outRng, rng1)
End If
End If
Next
Next
'I think the If statements should go here but i'm not sure
End Sub