Almost done need help

freerskys

New Member
Joined
Jul 24, 2014
Messages
29
Office Version
  1. 2010
Platform
  1. 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.
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
 

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,)

Forum statistics

Threads
1,214,870
Messages
6,122,019
Members
449,060
Latest member
LinusJE

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