Solved

looking for data in other worksheets in same workbook

Posted on 2012-03-16
10
211 Views
Last Modified: 2013-09-10
SHEETS 2 AND 3 COLUMN HEADERSSHEET1 COLUMN HEADERSexcel 2003 vba code needed( if possible)

What I have:
"Sheet1"  with column headers.
"Sheet2"  Contains Data
"Sheet3" Contains Data

Sheet 2 and 3 contain the same amount of COLUMNS
with headers...ColumnA : E
Column A on both Sheet 2 and 3 will contain the lookup value posted on Sheet1 in ColumnA



ColumnA(Sheet1) will contain the data to look for in the other sheets
Column B:E  will be additional data to return to the rows(on sheet1)  if value found in ColumnA in Sheet2 and Sheet3

Thanks
fordraiders
0
Comment
Question by:fordraiders
  • 6
  • 4
10 Comments
 
LVL 41

Expert Comment

by:dlmille
ID: 37731502
Hey, fordraiders!  Long time!

Can you provide a non-sensitive mock-up to make it a bit easier on us to help you?

Dave
0
 
LVL 3

Author Comment

by:fordraiders
ID: 37731615
Here is a mock up..

Column A in Sheet1 looks into ColumnA on sheet 2 and 3 and returns  B:E to Sheet1 in B:E



You can test by putting some numbers from Column A IN SHEET 2 OR 3 IN column A on sheet1
EE-Xref-Data-Pull.xls
0
 
LVL 41

Expert Comment

by:dlmille
ID: 37731683
So, you want a macro to populate the data on Sheet1, where the first column in sheet1 matches the first column in sheet2/sheet3.  If the match occurrs, you want to pull column B:E from the sheet2/sheet3 sheets into B:E in sheet1?

Like the attached?

Are you sure you don't just want to use formulas?

Anyway, confirm what I've put there as correct and I can give you VBA that pastes these formulas in then converts to values for all Sheet1 column A.

You've got the ball ;)

Dave
EE-Xref-Data-Pull.xls
0
 
LVL 3

Author Comment

by:fordraiders
ID: 37731703
dlmille, Yes correct...I'll take alook at the sheet
0
 
LVL 41

Expert Comment

by:dlmille
ID: 37731733
Here's your code.  Sorry, I couldn't integrate into your password protected VBA ;)

Option Explicit

Sub alignSheet1()
Dim wkb As Workbook
Dim wks1 As Worksheet
Dim wks2 As Worksheet
Dim wks3 As Worksheet
Dim rng As Range
Dim r As Range
Dim rFind As Range

    Set wkb = ActiveWorkbook
    Set wks1 = wkb.Worksheets("Sheet1")
    Set wks2 = wkb.Worksheets("Sheet3")
    Set wks3 = wkb.Worksheets("Sheet4")
    
    Set rng = wks1.Range("A2", wks1.Range("A" & wks1.Rows.Count).End(xlUp))
    
    For Each r In rng
        Set rFind = wks2.Range("A:A").Find(what:=r.Value, LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False)
        If Not rFind Is Nothing Then
            r.Offset(, 1).Resize(1, 4).Value = rFind.Offset(, 1).Resize(1, 4).Value 'copy B:E values
        Else
            Set rFind = wks3.Range("A:A").Find(what:=r.Value, LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False)
            If Not rFind Is Nothing Then
                r.Offset(, 1).Resize(1, 4).Value = rFind.Offset(, 1).Resize(1, 4).Value 'copy B:E values
            Else
                r.Offset(, 1).Resize(1, 4).Value = vbNullString
            End If
        End If
    
    Next r
End Sub

Open in new window


Dave
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Author Comment

by:fordraiders
ID: 37733272
sorry about that, I thought I cleared it...
dlmille-EE-Xref-Data-Pull.xls
0
 
LVL 41

Accepted Solution

by:
dlmille earned 500 total points
ID: 37733289
Ok - the app looks through column A and if match is found in the first or second sheet then it updates, otherwise it clears.

Code integrated into your workbook.

Dave
dlmille-EE-Xref-Data-Pull-r1.xls
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 37767717
Great Thanks !
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39471790
dimile, I have a question out like this one...but need to find...additiona matches if they exist.
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39481142
dimile, I hope you can help me.
I have a question re-posted on this same type of code.
Redmondd(Brian) has tried to help.
But does not fully undestand what I'm looking for in my opinion.
Can u please help !?

Thanks
fordraiders
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now