+ Reply to Thread
Results 1 to 8 of 8

Retrieving value from another sheet based on column

Hybrid View

  1. #1
    Registered User
    Join Date
    06-06-2011
    Location
    NC
    MS-Off Ver
    Excel 2011
    Posts
    10

    Retrieving value from another sheet based on column

    Hello guys,

    I've been working on a macro (with the help from this forum) that condenses data from multiple ranges to a new sheet. I'm almost done with the macro but I'm stuck on this one final part.

    I've attached an example but I'll explain the scenario.

    The raw datasets are in ranges that are 3 columns wide.
    the macro so far lists all the unique instances in the first sheet into one range.
    What I'm having trouble with is grabbing the counts from the ranges in sheet 1 to the condensed range.

    Can anyone point me in the right direction??

    Also, if anyone wants the macro I have so far, I would be glad to share it.
    Attached Files Attached Files
    Last edited by kookymonster; 06-24-2011 at 03:00 PM.

  2. #2
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: Retrieving value from another sheet based on column

    kookymonster

    Would you mind re-attaching the workbook with the code. It probably could be modified to do what you want.
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

  3. #3
    Registered User
    Join Date
    06-06-2011
    Location
    NC
    MS-Off Ver
    Excel 2011
    Posts
    10

    Re: Retrieving value from another sheet based on column

    Thanks for taking the time to take a look.

    This is the code I have so far. Everything up to
    " 'Gets counts from sheet 1" works. After that, i've just been trying out different things with no success

    
    Sub Unique()
    
    Dim Num_sources As Byte
    Dim I As Long
    Dim J As Long
    Dim K As Long
    Dim L As Long
    Dim Sheet1 As Worksheet
    Dim UniqueIPI As Worksheet
    Dim Title As String
    Dim Mycount As Long
    
    'All the source ranges
    Range("A3:C" & Range("C3").End(xlDown).Row).Name = "S1.ipi"
    Range("E3:G" & Range("G3").End(xlDown).Row).Name = "S2.ipi"
    Range("I3:K" & Range("K3").End(xlDown).Row).Name = "S3.ipi"
    Range("M3:O" & Range("O3").End(xlDown).Row).Name = "S4.ipi"
    Range("Q3:S" & Range("S3").End(xlDown).Row).Name = "S5.ipi"
    Range("U3:W" & Range("W3").End(xlDown).Row).Name = "S6.ipi"
    Range("Y3:AA" & Range("AA3").End(xlDown).Row).Name = "S7.ipi"
    Range("AC3:AE" & Range("AE3").End(xlDown).Row).Name = "S8.ipi"
    Range("AG3:AI" & Range("AI3").End(xlDown).Row).Name = "S9.ipi"
    Range("AK3:AM" & Range("AM3").End(xlDown).Row).Name = "S10.ipi"
    Range("AO3:AQ" & Range("AQ3").End(xlDown).Row).Name = "S11.ipi"
    Range("AS3:AU" & Range("AU3").End(xlDown).Row).Name = "S12.ipi"
    Range("AW3:AY" & Range("AY3").End(xlDown).Row).Name = "S13.ipi"
    Range("BA3:BC" & Range("BC3").End(xlDown).Row).Name = "S14.ipi"
    Range("BE3:BG" & Range("BG3").End(xlDown).Row).Name = "S15.ipi"
    Range("BI3:BK" & Range("BK3").End(xlDown).Row).Name = "S16.ipi"
    Range("BM3:BO" & Range("BO3").End(xlDown).Row).Name = "S17.ipi"
    Range("BQ3:BS" & Range("BS3").End(xlDown).Row).Name = "S18.ipi"
    Range("BU3:BW" & Range("BW3").End(xlDown).Row).Name = "S19.ipi"
    Range("BY3:CA" & Range("CA3").End(xlDown).Row).Name = "S20.ipi"
    Range("CC3:CE" & Range("CE3").End(xlDown).Row).Name = "S21.ipi"
    Range("CG3:CI" & Range("CI3").End(xlDown).Row).Name = "S22.ipi"
    Range("CK3:CM" & Range("CM3").End(xlDown).Row).Name = "S23.ipi"
    Range("CO3:CQ" & Range("CQ3").End(xlDown).Row).Name = "S24.ipi"
    Range("CS3:CU" & Range("CU3").End(xlDown).Row).Name = "S25.ipi"
    Range("CW3:CY" & Range("CY3").End(xlDown).Row).Name = "S26.ipi"
    Range("DA3:DC" & Range("DC3").End(xlDown).Row).Name = "S27.ipi"
    Range("DE3:DG" & Range("DG3").End(xlDown).Row).Name = "S28.ipi"
    
    Sheets.Add.Name = "UniqueIPI"
    Sheets("UniqueIPI").Activate
    Cells(1, 1).Value = "Unique IPI"
    Cells(2, 1).Value = "Description"
    Cells(2, 2).Value = "IPI"
    
    Sheets("Sheet1").Activate
    
    Num_sources = Application.InputBox(prompt:="Number of sources?", Title:="UniqueIPI V.1", Type:=1)
    
    Sheets("UniqueIPI").Activate
    
    For J = 1 To Num_sources
        Sheets("Sheet1").Range("S" & J & ".IPI").Copy _
        Destination:=Sheets("UniqueIPI").Range("A" & Rows.Count).End(xlUp).Offset(1)
    Next J
    
    'Removing Duplicates Part
    Columns(3).EntireColumn.Delete
    
    Sheets("UniqueIPI").Range("A3:C" & Range("C3").End(xlDown).Row).Select
    
    Sheets("UniqueIPI").Range("A3:C" & Range("C3").End(xlDown).Row).removeduplicates Columns:=2, Header:=xlNo
    
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Gathering Information from Sheet 1 Part'
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
     Range("A3:B" & Range("B3").End(xlDown).Row).Name = "Uniquedone.IPI"
     
     'Gathers Title from Sheet 1
     For L = 1 To Num_sources
        
        Sheets("Sheet1").Cells(1, 1 + 4 * (L - 1)).Copy _
        Destination:=Sheets("UniqueIPI").Cells(2, L + 2)
        Next L
    
    
    'Gets Counts from Sheet 1
        For K = 1 To Num_sources
        Cells(3, K + 2).Select
        Mycount = Application.CountA(Range("A:A"))
        ActiveCell.Value = WorksheetFunction.VLookup(B3, S1.IPI, 3, False)
        Selection.AutoFill Destination:=Range("C3:C&Mycount"), Type:=xlFillDefault
        Next K
        
        
        
        
        
    
    End Sub
    Last edited by kookymonster; 06-21-2011 at 03:52 PM.

  4. #4
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: Retrieving value from another sheet based on column

    Here is one way to move your data?

    Sub Get_Data()
    Dim cell As Object
    Dim r As Range
    Dim lrow As Long
    Dim x As Integer, i As Integer
    
    lrow = Sheets(1).Range("A65536").End(xlUp).Row
    Set r = Sheets(1).Range("A3:A" & lrow)
    For Each cell In r
    
    myid = cell.Offset(, 1).Value
    myval = cell.Offset(, 2).Value
        With Sheets(2)
            Set rFound = .UsedRange.Find(What:=myid, After:=.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
                            xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
                     
            If Not rFound Is Nothing Then
                rFound.Offset(, 1).Value = myval
            End If
        End With
    Next cell
    Set r = Sheets(1).Range("E3:E" & lrow)
    For Each cell In r
    
    myid = cell.Offset(, 1).Value
    myval = cell.Offset(, 2).Value
        With Sheets(2)
            Set rFound = .UsedRange.Find(What:=myid, After:=.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
                            xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
                     
            If Not rFound Is Nothing Then
                rFound.Offset(, 2).Value = myval
            End If
        End With
    Next cell
    Set r = Sheets(1).Range("I3:I" & lrow)
    For Each cell In r
    
    myid = cell.Offset(, 1).Value
    myval = cell.Offset(, 2).Value
        With Sheets(2)
            Set rFound = .UsedRange.Find(What:=myid, After:=.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
                            xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
                     
            If Not rFound Is Nothing Then
                rFound.Offset(, 3).Value = myval
            End If
                
        End With
    Next cell
    lrow = Sheets(2).Range("B65536").End(xlUp).Row
    With Sheets(2)
    For i = 3 To 5
        For x = 3 To lrow
            If Sheets(2).Cells(x, i).Value = vbNullString Then
                Sheets(2).Cells(x, i).Value = 0
            End If
        Next x
    Next i
    End With
     
    End Sub
    ...
    Thank You, Mike

    Some Helpful Hints:

    1. New members please read & follow the Forum Rules
    2. Use Code Tags...Place[code]Before the first line and[/code] After the last line.
    3. If you are pleased with a solution mark your post SOLVED.
    4. Thank those who have help you by clicking the scales at the top right of the post.

    Here...

  5. #5
    Registered User
    Join Date
    06-06-2011
    Location
    NC
    MS-Off Ver
    Excel 2011
    Posts
    10

    Re: Retrieving value from another sheet based on column

    realniceguy,

    Thanks for the code, I've tried it but it doesn't seems to work.
    It hangs up excel for a really long time.
    Do you have any ideas why that might be?

  6. #6
    Registered User
    Join Date
    06-06-2011
    Location
    NC
    MS-Off Ver
    Excel 2011
    Posts
    10

    Re: Retrieving value from another sheet based on column

    Realniceguy,

    I tested your code again after tweaking my ws a little bit and it works perfectly!
    However, i saw it only works for 3 ranges. In reality, I can have up to 28 ranges where I must retrieve information from. Is there a way to make it into a loop can could support x amount of ranges?

    Thanks,

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1