comparing values in a column against multiple sheets and returning subsequent values from other columns

Harry_1234

New Member
Joined
Aug 19, 2017
Messages
47
I am looking for a more sophisticated query to compare values of a column in a sheet against multiple sheets and if the value is found return values from a different column. I was able to achieve this with iferror and vlookup but i have about 20 sheets to compare values against.

Sheet1: (Column A is where the values exist to be compared against rest of the sheets and return the values in column B/C/D depending on whichever column has the status data in that particular sheet)
Name
RED
Orange
Blue

<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>
</tbody>


Sheet2:


<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>
</tbody>
NameStatus
REDDeployed

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>

<colgroup><col span="2"></colgroup><tbody></tbody>

Sheet3:
NameStageStatus
OrangeINot Deployed
BlueIINot Deployed

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>

Sheet1: (Final Result_
NameStatus
REDDeployed
OrangeNot Deployed
BlueNot Deployed

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this

Change the name of the "Status" column if necessary.
Code:
Sub [COLOR=#0000ff]comparing_values[/COLOR]()
  Dim sh As Worksheet, sh1 As Worksheet, c As Range, i As Range, j As Range, f As Long
  Set sh1 = Sheets("Sheet1")
  Application.Calculation = xlCalculationManual
  Application.ScreenUpdating = False
  For Each c In sh1.Range("A2", sh1.Range("A" & Rows.Count).End(xlUp))
    Application.StatusBar = "Processing row " & c.Row
    For Each sh In Sheets
      If sh.Name <> sh1.Name Then
        Set i = sh.Range("A:A").Find(c, , xlValues, xlWhole)
        If Not i Is Nothing Then
          Set j = sh.Rows(1).Find("[B][COLOR=#ff0000]Status[/COLOR][/B]", , xlValues, xlWhole)
          If Not j Is Nothing Then
            c.Offset(, 1).Value = sh.Cells(i.Row, j.Column).Value
            Exit For
          End If
        End If
      End If
    Next
  Next
  Application.Calculation = xlCalculationAutomatic
  Application.StatusBar = False
  MsgBox "End"
End Sub

HOW TO INSTALL MACROs
------------------------------------
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (comparing_values) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0

Forum statistics

Threads
1,215,241
Messages
6,123,824
Members
449,127
Latest member
Cyko

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