freerskys
New Member
- Joined
- Jul 24, 2014
- Messages
- 29
- Office Version
-
- 2010
- Platform
-
- Windows
Thanks in advance.
I have 2 sheets, sheet 1 column A-B has the original data.
Sheet 2 column A has the search data. If search finds value place the value in Sheet 2 column G else enter N/A, do this till the end of the data.
So far I can search find the value put it in column G(sheet2).
I need some help if search does not find anything, to enter N/A.
I have 2 sheets, sheet 1 column A-B has the original data.
Sheet 2 column A has the search data. If search finds value place the value in Sheet 2 column G else enter N/A, do this till the end of the data.
So far I can search find the value put it in column G(sheet2).
I need some help if search does not find anything, to enter N/A.
Code:
Sub CopyMatch()
'Sheet 1 = original data --Start A second Row
'Sheet 2 = search data --Start A Second Row
'Sheet 2 = results --Column G
Dim StartingScreenUpdateValue As Boolean
Dim StartingEventsValue As Boolean
Dim StartingCalculations As XlCalculation
Dim varTestValues As Variant
Dim sh1 As Worksheet
Dim sh2 As Worksheet
With Application
StartingScreenUpdateValue = .ScreenUpdating
StartingEventsValue = .EnableEvents
StartingCalculations = .Calculation
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
With sh2
varTestValues = .Range("A2", .Range("A" & .Rows.Count).End(xlUp))
End With
With sh1
.Range("A1", .Range("A" & .Rows.Count).End(xlUp)).AutoFilter Field:=1, _
Criteria1:=Application.Transpose(varTestValues), Operator:=xlFilterValues
.Range("B2", .Range("B" & .Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).Cells.Copy sh2.Range("G2")
varTestValues = .Range("G2", .Range("G" & .Rows.Count).End(xlUp))
.AutoFilterMode = False
End With
With Application
.ScreenUpdating = StartingScreenUpdateValue
.EnableEvents = StartingEventsValue
.Calculation = StartingCalculations
End With
MsgBox "Complete"
End Sub